Software System Engineering Dr M E Fayad Professor

  • Slides: 19
Download presentation
Software System Engineering Dr. M. E. Fayad, Professor Computer Engineering Department, Room #283 I

Software System Engineering Dr. M. E. Fayad, Professor Computer Engineering Department, Room #283 I College of Engineering San José State University One Washington Square San José, CA 95192 -0180 http: //www. engr. sjsu. edu/~fayad 10/3/2020

Lesson 6 -1: Object-Oriented Design Heuristics 2 © M. E. Fayad 1997 -2006 SJSU

Lesson 6 -1: Object-Oriented Design Heuristics 2 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 2 Design Heuristics - 1

Lesson Objectives Overview of Previous Lecture n Understand what do we mean by heuristics

Lesson Objectives Overview of Previous Lecture n Understand what do we mean by heuristics n Understand what is an object-oriented design heuristic? n Discuss the following: n – Macho Class Problem – Interesting Design Problems – Topology Which Needs Accessor Methods – The Common Traps of Controller Classes 10/3/2020 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 3 3 Design Heuristics - 1

CRC Cards General – Each class is described on a separate 3 X 5

CRC Cards General – Each class is described on a separate 3 X 5 or 4 X 6 card n The cards are known as CRC card. They have 3 sections: – Class – Responsibilities – Collaborations n ATM (role) Collaboration Responsibility Clients Access & modify account balance Account © M. E. Fayad 1997 -2006 SJSU – Cmp. E Server Balance Inquiry Deposit Transaction Funds Transfer Withdrawal Transaction M. E. Fayad L 6 -1 -S 4 4 Design Heuristics - 1

(1) Class Name (role (2)) - X Collaboration Responsibility Clients 1. 2. 3. 4.

(1) Class Name (role (2)) - X Collaboration Responsibility Clients 1. 2. 3. 4. Unique (3) The clients of One Responsibility the named Within Context class (X) (5) Indicate the role of the class What are the good, bad, and ugly of the CRC cards? © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad Server • • 4 -5 interfaces Services provided by the named class (X) (4) Other Names: Interfaces Commands Requests Functions Methods Procedures Processes L 6 -1 -S 5 5 Design Heuristics - 1

Guidelines n Pre- & Post-conditions n Statements that guide you to do something. n

Guidelines n Pre- & Post-conditions n Statements that guide you to do something. n It is not a process. n It is not a standards. n It is not a methodology n It is not a heuristic. n Direction or information about something. 6 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 6 Design Heuristics - 1

Object-Oriented Design Heuristics n An OO design heuristic is a “rule-of-thumb”, not a rule.

Object-Oriented Design Heuristics n An OO design heuristic is a “rule-of-thumb”, not a rule. n An OO design heuristic is something which makes a design “feel right” to its designer. n An OO design heuristic is used to guide a designer in selecting the appropriate design choice from many possibilities. n An OO design heuristic warns the designer of some impending doom when it is violated. 7 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 7 Design Heuristics - 1

Object-Oriented Design Heuristics n While some design heuristic certainly imply a sense of priority,

Object-Oriented Design Heuristics n While some design heuristic certainly imply a sense of priority, there cannot be a prioritized ordering of the entire list (in general). n It is not possible to follow all heuristics in a design. They frequently have colliding interests such as extensibility versus complexity. n A design heuristic will tell users of design patterns when a particular pattern needs to be applied. © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 8 8 Design Heuristics - 1

Design Patterns: Properties & Definitions n [Webster] A pattern is a fully realized form,

Design Patterns: Properties & Definitions n [Webster] A pattern is a fully realized form, original, or model accepted, or proposed for imitation. n [Webster] A pattern is something regarded as normative example to be copied; archetype ; exemplar. n [Alexander 79] A pattern is a solution to a problem in a context. n [Alexander 79] A pattern has three parts: – Problem(s) – Context – Solution n A pattern offers a workable solutions. n Patterns are rules of thumbs that can be used again and again -useful, practical “how-to” guideline. © M. E. Fayad 1997 -2006 9 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 9 Design Heuristics - 1

Design Patterns: More Properties & Definitions n [Gamma 95. ] Design patterns identify, name,

Design Patterns: More Properties & Definitions n [Gamma 95. ] Design patterns identify, name, and describe common and recurring designs appearing frequently in object-oriented systems. n [Gamma 95] You can think of a design pattern as a micro architecture that contributes to overall system architecture. n Each design pattern tends to be relatively small in size and scope. n [Coplien 92] Patterns are a way of describing, documenting, and creating system architectures for software. n Patterns tend not to be domain specific. n Patterns are one of the primary mechanisms that people use for passing on expertise to others. © M. E. Fayad 1997 -2006 10 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 10 Design Heuristics - 1

Object-Oriented Design Heuristics n Heuristic Properties: – A heuristic is a “rule-of-thumb but not

Object-Oriented Design Heuristics n Heuristic Properties: – A heuristic is a “rule-of-thumb but not a rule. – Heuristics attempt to capture the unknown “feels right” feature of good analysis, good design, good documentation, etc. – Heuristics are strongly related to patterns in that they provide the rational for improving a design from a worse pattern to a better one. – All of the interesting heuristics are qualitative in nature. – There are no useful quantitative heuristics © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 11 11 Design Heuristics - 1

Object-Oriented Design Heuristics n The absence of quantitative heuristics leads us to conclude that

Object-Oriented Design Heuristics n The absence of quantitative heuristics leads us to conclude that OO design is not precise. n Some amount of fuzziness is required and only qualitative heuristics can accommodate this constraints. n For an example of this fuzziness consider the following two important design heuristics that play off each other in an attempt to model the top level view of a system – A designer should distribute system intelligence uniformly among the top level classes in the system – A designer should minimize the number of collaborations on the top level of the system. © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 12 12 Design Heuristics - 1

Object-Oriented Design Heuristics n It is typical for designers to want the seemingly more

Object-Oriented Design Heuristics n It is typical for designers to want the seemingly more useful quantitative metrics such as – A designer should have 4. 6 top level classes per 1, 000 lines of code. – A designer should have 35 to 45 percent of the relationships in a design be uses relationships. n These heuristic are not useful and very misleading. 13 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 13 Design Heuristics - 1

What is an Object? n An object will always have four facets: 1. Identity

What is an Object? n An object will always have four facets: 1. Identity (this might be only its address in memory. 2. Attributes of its class (usually static) & values of those attributes (usually dynamic). 3. Behavior of its class (the implementor’s view) 4. Public interface of its class (user’s view) 14 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 14 Design Heuristics - 1

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 1: All

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 1: All data should be hidden within its class. n Heuristic 2. 2: Users of a class must be dependent on its public interface, but a class should not be dependent on its users. n Heuristic 2. 3: Minimize the number of messages in the protocol of a class n Heuristic 2. 4: Implement a minimal public interface. n Heuristic 2. 5: Don’t put implementation details such as common-code private functions into the public interface of a class. 15 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 15 Design Heuristics - 1

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 6: Don’t

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 6: Don’t clutter the public interface of a class with items that users of that class are not able to use or are not interested in using. n Heuristic 2. 7: Classes should only exhibit nil or export coupling with other classes, that is, a class should only use operations in the public interface of another class or have nothing to do with that class. n Heuristic 2. 8: A class should capture one and only one key abstraction. 16 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 16 Design Heuristics - 1

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 9: Keep

Classes & Objects: The Building Blocks of OO Paradigm n Heuristic 2. 9: Keep related data and behavior in one place “localization” n Heuristic 2. 10: Spin off non-related information into another class (i. e. , non-communicating behavior) n Heuristic 2. 11: Be sure the abstractions that you model are classes and not simply the roles objects play. 17 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 17 Design Heuristics - 1

Discussion Questions • T/F statements 1. Objects should be intelligent agents 2. Type names

Discussion Questions • T/F statements 1. Objects should be intelligent agents 2. Type names an interface. 3. A valuable object works and plays well with others 4. Design patterns identify, name, and describe common and recurring designs appearing frequently in object-oriented systems. 5. Design patterns are domain independent. • © M. E. Fayad 1997 -2006 Define: legacy systems, method, message, interface SJSU – Cmp. E M. E. Fayad L 6 -1 -S 18 18 Design Heuristics - 1

Questions for the Next Lecture Define: – Macho classes – Accessor Methods – Controller

Questions for the Next Lecture Define: – Macho classes – Accessor Methods – Controller Classes – Classes & objects in UML 19 © M. E. Fayad 1997 -2006 SJSU – Cmp. E M. E. Fayad L 6 -1 -S 19 Design Heuristics - 1