Download presentation
Presentation is loading. Please wait.
Published byHannah Boone Modified over 8 years ago
1
Rohini Sharma Roll No. RA1809A01 Regd. No. 40800065 M.Tech.(CSE) Part Time 3 rd Semester.
2
Contents Object Oriented Concepts Coupling in OOS Cohesion in OOS Conclusion
3
Object Oriented Concepts Object: Encapsulation of state & behavior Inheritance Hierarchy: A class inherits instance variables and methods from another class. This relationship is transitive, reflexive and antisymmetric. Message Passing: Implies interaction relationship. Only means for an object to access and alter another object’s state. Overriding: Redefinition of inherited instance variables and methods in subclasses. Polymorphism: Same method may be invoked on objects of different classes. Dynamic Binding: Binding b/w method invocation and code to be executed takes place during runtime.
4
Coupling Factor of dependency of one class on another class or one object on another object. High coupling system are Unstable Require more effort to modify Leads to ripple effect Increases Cost Decreases reusability First formal definition given by Chidamber & Kemerer: “…any evidence of a method of one object using methods or instance variables of another object constitutes coupling”
5
Types of Coupling Content Coupling- One class use variable of another class. How to reduce: Private access. Common Coupling-Classes share global data. How to reduce: Class containing global data with public methods. External Coupling-Dependency of classes on third party classes like MFC. How to reduce: Use Façade Pattern Control Coupling-One class controls logic or sequence of execution of another class. How to reduce: Using Polymorphic operations. Contd../
6
Stamp Coupling-Two classes modify or access data in the same object. How to reduce: Use methods. Data Coupling-One class passes data to another as an argument. How to reduce: Pass few arguments containing abstract information Message Coupling-Lowest possible Coupling. Routine Call Coupling-When one routine calls another. How to reduce: Keep routine calls minimum. Sequence of calls be encapsulated in single routine. Inclusion Coupling-One component includes source code of another component. How to reduce: Components not required should not be included.
7
Importance of Coupling in OOS Change dependencies of server on client. Hard to understand an object in isolation. High coupling increases probability of remote effects. Loose coupling helps in tracking error, thus increases testability, eases debugging.
8
Broad Classification of Coupling Loose Coupling Dependent Class contains pointer to interface. Provides extensibility to designs. TestingShape Interface Draw() Erase() Area() Circle Draw() Erase() Area() Rectangle Draw() Erase() Area() Triangle Draw() Erase() Area() Fig. 1: Loose Coupling 1
9
Strong Coupling Dependent class contains pointer to concrete class. Fig. 2: Strong Coupling TestingShape Draw() Erase() Area() 1
10
Measuring Coupling Coupling between two classes A and B increases if A has an attribute that refers to B. A calls on services of an object B. A has a method which references B via return type or parameter. A is a subclass of B. Loose Coupling is measured by noting the number of changes in data elements that could occur without changing the way systems communicate to each other Adding new data elements to messages. Changing the order of data elements. Changing the names of data elements. Changing the structures of data elements. Omitting data elements.
11
Performance Issues Message Creation Overhead and Performance Longer Messages require more CPU time and memory Message Transmission Overhead and Performance Longer Messages require more CPU time and memory Message Translation Overhead and Performance Message form and content must be reduced and refined to maximize its meaning and reduce translation. Message Interpretation Overhead and Performance Complex messages may require string transformer to exhibit intended meaning.
12
Cohesion Generally Cohesion is a measure of how strongly related and focused the various modules of a software are. In Object Oriented Paradigm, if the methods serving the given class tend to be similar in many aspects, then class is said to have high Cohesion. Cohesion decreases if: The responsibilities (methods) of a class have little in common. Methods carry out many varied activities.
13
High Cohesion leads to: Robustness Reliability Reusability Understandability Low Cohesion leads to: Difficulty to testing Difficulty to reuse Difficulty to understand Difficulty to maintain
14
Types of Cohesion in OOS Method Cohesion Class Cohesion Inheritance Cohesion
15
Method Cohesion Seven degrees defined from weakest to strongest Coincidental (worst)- Parts have no significant relation. Logical Cohesion- Only logical similarity Temporal- Parts execute at same time Procedural Cohesion- Parts follow certain sequence of execution Communicational- Parts are connected by control flow and operate on same set of data Sequential- Parts have communicational cohesion and connected by sequential control flow Functional (best)- Parts contribute to a single task and are sequentially cohesive. Mostly Communicational Cohesion is the highest level of Cohesion achieved.
16
Class Cohesion Addresses relationship between non-inherited methods and non-inherited attributes of a class. Four degrees from weakest t strongest are defined: Separable- When objects of a class represent multiple unrelated data abstractions. Multifaceted- When objects of a class represent multiple related data abstraction. Alternatively when relational schema representing the class is not in second normal form Contd../ Class Order{ item orderitem; company Fromorder int discount; int quantity; ….. Public bool exprevenue() …}
17
Non-delegated- When certain attributes do not describe the whole data abstraction represented by class, but only a component of it. Alternatively when relational schema representing the class is not in third normal form Contd../ Class Employee{ String name; Date birthdate; Project curpro; Employee projmanager; ….. Public float compsal(); …}
18
Concealed- When useful data abstraction is concealed in data abstraction represented by class. Class Employee { int dayofbirth; int monofbirth; int yearofbirth; int dayofhire; int monofhire; int yearofhire; }
19
Inheritance Cohesion Describes binding of newly defined elements together with the inherited elements. Inheritance Cohesion is strong if hierarchy is generalization hierarchy and weak if hierarchy is merely used for code sharing among otherwise unrelated classes. Weak Inheritance Cohesion makes system difficult to understand, maintain and reuse.
20
Measuring Cohesion Five graphical metrics that use inheritance cohesion and class cohesion to asses design quality of inheritance hierarchy: Inheritance Cohesion versus Inheritance Level. Average Inheritance Cohesion of Children versus Number of Children of Parent Classes. Inheritance Cohesion versus Number of Overridden Methods. Class Cohesion of Parent Classes versus Number of Children. Class Cohesion versus Number of Implemented Methods.
21
Inheritance Cohesion v/s Inheritance level The graph should be horizontal ie. Cohesion does not change as we move down the hierarchy. If graph level drops it means inheritance have been misused. If plot rises up, it means children classes are more cohesive than parents. Two types of graphs used: Cohesion of classes sorted in increasing order of Inheritance level Average Inheritance Cohesion v/s Inheritance Level.
22
Cohesion of classes sorted in increasing order of Inheritance level: Average Inheritance Cohesion v/s Inheritance Level. Fig. 4: Plot for a system of four classes. Fig. 5: Plot for four inheritance level
23
Average Inheritance Cohesion of Children versus Number of Children of Parent Classes. Super Class may be used as ‘Container of Service Methods’. Designer might include more and more classes as direct children to save coding. Fig. 6: Plot for system with four non-leaf classes
24
Inheritance Cohesion versus Number of Overridden Methods. If a class overrides some of the methods such that implementation is completely changed, cohesion of subclass can be adversely affected. Fig. 7: Plot for system of four classes
25
Class Cohesion of Parent Classes versus Number of Children. Sometimes superclass is used as ‘Container of Service Methods’ that are usually unrelated in superclass and fulfills the requirement of subclasses only. Fig. 8: Plot for system with four non-leaf classes.
26
Class Cohesion versus Number of Implemented Methods. A class with large number of implemented methods may be less cohesive as the class may abstract more than one entity. Fig. 9: Plot for system of four classes.
27
THANK YOU
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.