5
Ch. 2 Discussion Head First Java

Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Embed Size (px)

Citation preview

Page 1: Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Ch. 2 Discussion

Head First Java

Page 2: Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Big Idea

• Differene between a class and an object• What benefit object-oriented programming

gives you.• Read “Chair Wars”– Larry v. Brad – procedural v. object-oriented

• Application to put a shape on a screen.• Differences between procedural programming

v. classes – reusable code.

Page 3: Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Object Oriented

• A “Class” for each shape• P. 29 – a specification change• Larry has to put changes into many lines of

code• Brad creates a new “class”• P. 30 – another new specification – • Brad has less work than Larry as he modifies

the Amoeba class.

Page 4: Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Chair Wars - continued

• P. 31 –– Rotate method in all of Brad’s shapes– Duplicate Code

• Final Design – Inheritance – advanced concept– Power behind it all

• Brad looked at what all four have in common– He pulled out all of the common features and put

them into a generic class – shape.– All four shapes “inherit” from the Shape class.

Page 5: Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”

Chair Wars

• Shape is a “superclass”• All four shapes are related and “inherit” the

characteristics of the superclass.• Square, circle, triangle, amoeba – subclass.• Page 32 – Amoeba class can over-ride the

methods from Shape.• Any changes to Shape impact all the subclasses.• The use of “classes” is essential to OOP