Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch4: Software Architecture and Design. 1 Specialization and generalization inheritance  Specialization:  Generalization  General parent class customized.

Similar presentations


Presentation on theme: "Ch4: Software Architecture and Design. 1 Specialization and generalization inheritance  Specialization:  Generalization  General parent class customized."— Presentation transcript:

1 Ch4: Software Architecture and Design

2 1 Specialization and generalization inheritance  Specialization:  Generalization  General parent class customized to include more data, more methods or both.  Child class special case of parent class.  Good form of inheritance.

3 2 Specialization and generalization inheritance - Example class PItem : public Item { protected: food_state Environ; int Days; void ItemSpecificPrint(); public: virtual void CreateNewItem(); virtual void PrintItem(); virtual void PrintPerish(); virtual void UpdateItem(); void PrintDaysFoodState(); }; class DeliItem : public PItem {protected: float Weight; float CostPerLb; void ItemSpecificPrint(); public: virtual void CreateNewItem(); virtual void PrintItem(); virtual void PrintPerish(); virtual void UpdateItem(); void PrintWeightandCost(); }; Item / \ NonPItem PerishItem / \ \ DeliItem DairyItem ProduceItem Generalization Specialization Food state: shelf, expiration data Weight & cost:

4 3 Specification inheritance and example GraphicalObject / \ \ Ball Wall Hole Data-Oriented Menu / \ PrintMenu SaveMenu Function-Oriented

5 4 Construction inheritance and example Dictionary / \ SymbolTable HashTable LinkedList / \ \ Queue Set Stack

6 5 Variance inheritance and example PointingDevice / \ \ TouchPad Mouse Tablet

7 6 Combination inheritance and example Faculty Student \ / TeachingAsst MeatItem ProduceItem \ / DeliItem

8 7 Generalization inheritance and example Window | ColoredWindow Window displays white background. ColoredWindow allows the background to be other than white.

9 8 Extension inheritance and example Set | StringSet StringSet class has additional string-related operations

10 9 Limitation inheritance and example DEQueue / \ Queue Stack / \ LIFO FIFO Key issues: Going from a bi-directional queue to limited abstractions Limiting functionality

11 10 Overloading  Ability to define two or more methods with the same names and different signatures:  OO design and programming allows us to define our own types (classes)

12 11 Overloading – Stack example class stack { private: char* st, top; int size; public: void stack(int x) {top = st = new char[x]; size = x;} void stack() {top = st = new char[100]; size = 100;} // push, pop, top, etc., Omitted }; main() { stack S1(10); // Creates a char Stack with 10 Slots stack S2; // Default, no Parameter Supplied // Creates a char Stack with 100 Slots // Size of S2 Might not be Known to User! } 2015105 S1 2015105 S2 … etc...

13 12 Overloading in HTSS class Item { private: int UPC, OnShelf, InStock, ROLimit; // Etc... As Previously Given public: Item(); // The Constructor // Etc... Others as Previously Given Item operator--(){ this->OnShelf--; this->InStock--; } }; main() { Item I1; Status s; s = I1.Create_New_Item(123, OJ, 10, 30,...); I1--; // Reduces I1.OnShelf and I1.InStock // Now Contain 9 and 29 Respectively } Overloads the operator --

14 13 Polymorphism: Definition Variables P: Person; F: Faculty; S: Student; //Supertype can Hold Instance of //Subtype, but NOT REVERSE! P = F; // Treat Faculty as Person P = S; // Treat Student as Person P FS

15 14 Polymorphism/dispatching: illustration Person Name SSN Employee Dept. Yrs. Student Dorm GPA Faculty Rank Dean School Undergrad Year Grad Program Degree Suppose, we want to define print_info() for each class? What is true for all persons?

16 15 Polymorphism/dispatching: illustration Print_Info methods defined as follows: Person::Print_Info() {Prints Name and SSN} Employee::Print_Info() {Calls Person::Print_Info(); Prints Dept and Yrs; } Student::Print_Info() {Calls Person::Print_Info(); Prints Dorm and GPA; } Faculty::Print_Info() {Calls Employee::Print_Info(); Prints Rank; } Print_Info Also for Dean, UnderGrad, Grad

17 16 Polymorphism/dispatching: illustration Person p = new Person(); p.print_info(); Faculty f = new faculty(); f.print_info(); Person fp = f; fp.print_info(); The print_info() method invoked on fp depends on the run time type of the object fp (faculty) and not on the compile time type of the object. Run time type of object fp is faculty, not person.

18 17 Polymorphism and dispatching: definition  Polymorphism via dispatching:  Benefits of polymorphism/dispatching:  Polymorphism/dispatching incurs cost or overhead both at compile and runtime  Efficiency is lost, cannot determine the method at compile time.

19 18 Substitutability  Principle of substitutability:  Implications of substitutability:  Example:

20 19 Important implementation concepts  Message passing:  Automatic variables:  Dynamic variables:

21 20 Important implementation concepts (contd..)  Lifetime:  Scope:  Immutable values:  Typing of variables:  Strongly typed languages (Ada95 and Java)

22 21 Important implementation concepts (contd..)  Static binding:  Dynamic binding:  Early binding vs. late binding


Download ppt "Ch4: Software Architecture and Design. 1 Specialization and generalization inheritance  Specialization:  Generalization  General parent class customized."

Similar presentations


Ads by Google