Week 08 - Constructors, Class Hierarchy, Design

H animalsmaincc shapesh shapesmaincc class hierarchy

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tends (functionalities/properties) of an Animal ● Diagraming class hierarchies ○ animals.h, animals_main.cc ○ shapes.h, shapes_main.cc Class Hierarchy & Functions class Plant { }; class Tobacco : Plant { }; void grow(Plant p); void smoke(Tobacco t); ● grow can receive a Plant or a Tobacco object ● smoke can receive only a Tobacco object ● Recall the "is a" rule Class Inheritance vs. Class Attribute ● Inheritance: "is a" ○ "Car is an Engine" (bad design, doesn't make sense!) ■ class Engine { }; class Car : Engine { }; ● Attribute: "has a" ○ "Car has an Engine" (good design, makes sense!) ■ class Engine { }; class Car { Engine engine; } Project 7...
View Full Document

This note was uploaded on 04/05/2013 for the course CS CS 31 taught by Professor Smallberg during the Winter '11 term at UCLA.

Ask a homework question - tutors are online