Download presentation
Presentation is loading. Please wait.
Published byKellie Sims Modified over 8 years ago
1
Ch4: Software Architecture and Design
2
1 Categories of classes Data Managers: class Item { private: // Private Data int UPC; char* Name; int InStock, OnShelf, ROLimit; float RetailCost; public: // Public Methods Item(int code, char* str, int st1, int st2, int st3, float cost); void CreateNewItem(); int GetUPC(); char* GetName(); int GetQuantity(); int CheckReorderStatus(); void PrintItem(); void UpdatePrice(float new_value); };
3
2 Categories of classes (contd..) class ItemDB {private: int Num_Items; int Curr_Item; Item* AllItems[Max_Items]; int FindFirstItem(); int FindNextItem(); int FindItemUPC(int code); int FindItemName(char* name); public: ItemDB(); // Constructor void InsertNewItem(Item* new_one); void DeleteExistingItem(int code); void FindDisplayItemUPC(int code); void FindDisplayItemName(char* name); void PrintAllItems(); }; Data sinks/data sources:
4
3 Categories of classes (contd..) I1 “milk” I2 “peas” I3 “soda” ItemDB Data Manager class Data Source/Sink class Data Source/Sink class is added for implementation.
5
4 Categories of classes (contd..) View/Observer: Provide an interface for user - class InvControlGUI { private: int Curr_Option; // Current menu option public: InvControl(); // Constructor void PrintMenuSetOption(); void ActivateController(); void EnterNewItem(); void RemoveExistingItem(); void FindItem(); void InvSearchQuantity(); void InvSearchReorder(); void GenerateAnOrder(); };
6
5 Categories of classes (contd..) Facilitator/Helper – Used to support complex tasks For HTSS, Facilitator/Helpers are as follows:
7
6 Common design flaws Classes that directly modify the private data of other classes E.g. class Item from HTSS Change RetailCost via UpdatePrice() Do not access RetailCost directly class Item { private: // Private Data float RetailCost; public: // Public Methods void UpdatePrice(float new_value); };
8
7 Common design flaws (contd..) Too much functionality in one class class Item { protected: // Attributes as given in earlier examples public: // Two constructors for versatility int GetUPC(); char* GetName(); int GetInstockAmt(); int GetOnShelfAmt(); int GetQuantity(); int GetReorderAmt(); float GetRetailPrice(); float GetWholeSaleCost(); void UpdateName(char* item_name); void UpdateInstockAmt(int stock_amt); void UpdateOnShelfAmt(int shelf_amt); void UpdateReorderAmt(int reord_amt); void UpdateRetailPrice(float price); void UpdateWholeSaleCost(float wholesale); } void PrintUPCName(); void PrintNamePrice(); void PrintInventory(); void PrintProfitInfo(); void PrintUPC(); void PrintName(); void PrintInstockAmt(); void PrintOnShelfAmt();
9
8 Common design flaws (contd..) A class that lacks functionality: Classes that have unused functionality Classes that duplicate functionality
10
9 Common design flaws (contd..) What’s in a name? Remember, somebody else who comes after you has to understand and maintain what you develop!
11
10 Inheritance: Motivation Consider a software application written for a university Four types of individuals and their attributes have been identified: Faculty Dean UnderGrad Grad Name Name Name Name SSN SSN SSN SSN Rank School Dorm Dorm Dept Dept Year Program Yrs Yrs GPA Degree GPA To successfully utilize inheritance:
12
11 Inheritance: Motivation Person Faculty: Person Dean:Person Name Rank School SSN Dept. Dept. Years Years Undergrad: Person Grad: Person Dorm Dorm Year Program GPA Degree GPA Person Faculty Dean Undergrad Grad
13
12 Inheritance: Motivation Person Name SSN Employee Student Dept. Dorm Yrs. GPA Faculty Dean Undergrad Grad Rank School Year Program Degree
14
13 Inheritance: Motivation Person Name SSN Employee Student Dept. Dorm Yrs. GPA Faculty Dean Undergrad Grad Rank School Year Program Degree
15
14 Inheritance: Definition What is inheritance? Generalization and specialization: Subclass is more refined than superclass – its specialized Superclass contains common characteristics of its subclasses – its generalized
16
15 Inheritance: Definition When can inheritance be used? Inheritance permits reuse:
17
16 Role of inheritance Develop inheritance hierarchies that are: Utilization of inheritance: How Benefits of inheritance: Why Impact of inheritance: Cost
18
17 Benefits of inheritance Software reusability Design and code sharing
19
18 Benefits of inheritance (contd..) Software components Rapid prototyping All benefits apply to design, development and maintenance
20
19 Cost of inheritance Execution speed: Gen. purpose solution, not faster. Program size: Large libraries, but memory size not a factor. Platform independence (Java) impacts both speed and size.
21
20 Cost of inheritance (contd..) Message passing overhead: Search class, parent, grandparent etc. for the right method. Program complexity: Train SEs. CFG understanding may need multiple scans up/down.
22
21 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.
23
22 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:
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.