Upload
rosalyn-stokes
View
212
Download
0
Embed Size (px)
Citation preview
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”– Larry v. Brad – procedural v. object-oriented
• Application to put a shape on a screen.• Differences between procedural programming
v. classes – reusable code.
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.
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.
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