slide 1 chapter 10 class and method design. slide 2 revisiting the basic characteristics of...
Post on 21-Dec-2015
224 views
TRANSCRIPT
Slide 1
Chapter 10Class and Method Design
Slide 2
REVISITING THE BASIC CHARACTERISTICS OF OBJECT-ORIENTATION
Slide 3
Levels of Abstraction
Package
Slide 4
Elements
ClassesObjectsAttributesStatesMethodsMessages
Slide 5
Encapsulation
Hiding the content of the object from outside viewCommunication only through object’s methodsKey to reusability
Slide 6
Polymorphism
Same message triggers different methods in different objectsDynamic binding means specific method is selected at run timeImplementation of dynamic binding is language specificNeed to be very careful about run time errorsNeed to ensure semantic consistency
Slide 7
Inheritance
Single inheritance -- one parent classMultiple inheritance -- multiple parent classesRedefinition and inheritance conflictMost inheritance conflicts are due to poor classification
Slide 8
Rumbaugh’s Rules
Query operations should not be redefined
Methods that redefine inherited ones should only restrictthe semantics of the inherited ones
The underlying semantics of the inherited method should never be changed
The signature (argument list) of the inherited method shouldnever be changed
Slide 9
Additional Inheritance Conflicts
Two inherited attributes or methods have same name and semanticsTwo inherited attributes or methods have different name, but same semanticsTwo inherited attributes or methods have same name and different semantics
Slide 10
Inheritance Conflicts with Multiple Inheritance
Slide 11
Design Criteria
Slide 12
Coupling
Indicates the interdependence or interrelationships of the modulesInteraction coupling
Relationships with methods and objects through message passage
Inheritance couplingHow tightly coupled are the classes in the inheritance hierarchy?
Slide 13
Interaction Coupling
Cohesion
Slide 14
Determines how single-minded a module (class, object, or method) is within a systemMethod Cohesion
Methods should do one and only one thing
Class CohesionLevel of cohesion between the attributes and methods of a class
Slide 15
Types of Method Cohesion
Slide 16
Ideal Class Cohesion
Contain multiple methods that are visible outside the classHave methods that refer to attributes or other methods defined with the class or its superclassNot have any control-flow coupling between its methods
Slide 17
Types of Class Cohesion
Slide 18
Connascence
Two modules (classes or methods) are so intertwined, that if you make a change in one, it is likely that a change in the other will be requiredGeneralizes the idea of cohesion and coupling
Slide 19
Connascence and Encapsulation Levels
Minimize overall connascence by eliminating any unnecessary connascence throughout the system,Minimize connascence across any encapsulation boundaries, such as method boundaries and class boundaries, Maximize connascence within any encapsulation boundary.
Slide 20
Types of Connascence
Slide 21
Object Design Activities
1. Adding Specification2. Identifying opportunities for reuse3. Restructuring the design4. Optimizing the design5. Mapping problem classes to Implementation
Languages
Slide 22
1. Additional SpecificationEnsure the classes are both necessary and sufficient for the problemFinalize the visibility of the attributes and methods of each classDetermine the signature of every method of each classDefine constraints to be preserved by objects
Slide 23
2. Identifying Opportunities for Reuse
Analysis patternsProblem domain representations
Design patternsGrouping of collaborating classes that provide a solution to a commonly occurring problem
FrameworksSet of implemented classes that can be used as a basis for implementing an application. E.g: CORBA, DCOM
LibrariesSet of class libraries
ComponentsSelf-contained, encapsulated piece of software that can be plugged-in
Slide 24
Sample Design Pattern(Forwarder-Receiver Pattern)
Slide 25
3. Restructuring the Design
Factoring Separate aspects of a method or class into a new method or class
NormalizationIdentifies classes missing from the design
Challenge inheritance relationships to ensure they only support a generalization/specialization semantics
Slide 26
4. Optimizing the Design
Review access paths between objectsReview each attribute of each classReview fan-out of each methodExamine execution order of statementsCreate derived activities
Slide 27
5. Map Problem Domain Classes to Implementation Languages
Single-Inheritance LanguageConvert relationships to association relationshipsFlatten inheritance hierarchy by copying attributes and methods of additional superclass(es)
Slide 28
Implement in Object-Based Language
Factor out all uses of inheritance from the problem domain class design
Slide 29
Implement in a Traditional Language
Stay away from traditional languages to implement O-O designBut if necessary, factor out all uses of
PolymorphismDynamic bindingEncapsulationInformation hiding
Slide 30
Constraints and Contracts
Slide 31
Types of Constraints
Pre-ConditionsA constraint to be met to allow a method to execute
Post-conditionA constraint to be met after a method executes
InvariantsConstraints that must be true for all instances of a class
Slide 32
Invariants
Slide 33
Elements of a Contract
Slide 34
Method Specification
Slide 35
Method Specification
General informationEventsMessage passingAlgorithm specification
Structured EnglishPseudocodeUML activity diagram
Slide 36
Applying the Concepts at CD Selections
Slide 37
Revised CD Selections Class Diagram
Slide 38
Back of CD CRC Card
Slide 39
Get Review Method Contract
Slide 40
Revised Package Diagram