{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}


L14_Inheritance - OOP components Inheritance For COP 3330...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Inheritance For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Piyush Kumar OOP components | Data Abstraction z Information Hiding, ADTs | Encapsulation | Type Extensibility z Operator Overloading | Inheritance z Code Reuse | Polymorphism “Is a” Vs “Has a” Inheritance Considered an “Is a” class relationship e.g.: An HourlyEmployee “is a” Employee A Convertible “is a” Automobile A class contains objects of another class as it’s member data Considered a “Has a” class relationship e.g.: One class “has a” object of another class as it’s data Another Example class Car : public Vehicle { public: // ... }; We state the above relationship in several ways: * Car is "a kind of a" Vehicle * Car is "derived from" Vehicle * Car is "a specialized" Vehicle * Car is the "subclass" of Vehicle * Vehicle is the "base class" of Car * Vehicle is the "superclass" of Car (this not as common in the C++ community) Vehicle Car UML Virtual Functions | Virtual means “overridable” | Runtime system automatically invokes the proper member function. | Costs 10% to 20% extra overhead compared to calling a non-virtual function call. Virtual Destructor rule | If a class has one virtual function, you want to have a virtual destructor. | A virtual destructor causes the compiler to use dynamic binding when calling the destructor. | Constructors: Can not be virtual. You should think of them as static member functions that create objects.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Pure virtual. | A pure virtual member function is a member function that the base class forces derived classes to provide. | A pure virtual function makes a class an abstract base class (ABC) z Can not be instantiated! | An ABC can also have a pure virtual destructor. Pure virtual member functions. | Specified by writing =0 after the function parameter list. OOP Shape Example shape rectangle triangle circle • • • • Public inheritance: “Is A” relationships ABC Abstract Base class: Shape.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}