Unformatted text preview:

Object Oriented Design Kenneth M Anderson Lecture 20 CSCI 5828 Foundations of Software Engineering OO Design 1 Object Oriented Design Traditional procedural systems separate data and procedures and model these separately Object orientation combines data and methods together into a cohesive whole data abstraction The purpose of Object Oriented OO design is to define the classes and their relationships that are needed to build a system that meets the requirements contained in the SRS OO Design 2 OO A D OO techniques can be used in analysis requirements as well as design The methods and notations are similar In OO analysis we model the problem domain while in OO design we model the solution domain Often structures created during OO analysis are subsumed reused extended in the structures produced by OO design The line between OO analysis and OO design is blurry as analysis structures will transition into model elements of the target system OO Design 3 Relationship of OO A D OO Design 4 OO Concepts Encapsulation grouping of related ideas into one unit which we can refer to by a single name For example methods classes packages Provides information hiding by restricting the external visibility of a unit s information In OO A D the object is the unit of encapsulation An object s data is hidden behind the public interface methods of the object OO Design 5 OO Concepts State Retention Identity each object can be identified and treated as a distinct entity the functions of function oriented design do not retain state an object on the other hand is aware of its past and maintains state across method invocations very important issue see lecture 10 Behavior state and methods together define the behavior of an object or how an object responds to the messages passed to it OO Design 6 OO Concepts Classes a class is a stencil from which objects are created defines the structure and services of a class of objects A class has An interface which defines which parts of an object can be accessed from outside A body that implements the operations Instance variables to hold object state Objects and classes are different a class is a type an object is an instance State and identity is associated with objects OO Design 7 OO Concepts access Operations in a class can be Public accessible from outside Private accessible only from within the class Protected accessible from within the class and from within subclasses OO Design 8 Inheritance Inheritance is unique to OO and not available in function oriented languages models If class B inherits information from class A it implicitly acquires the attributes and methods of A Attributes and methods of A are reused by B When B inherits from A B is the subclass or derived class and A is the base class or superclass OO Design 9 Inheritance A subclass B generally has a derived part inherited from A as well as new attributes new instance variables or methods B s specification only defines the new attributes This creates an is a relationship objects of type B are also objects of type A OO Design 10 Inheritance OO Design 11 Inheritance The inheritance relationship between classes forms a class hierarchy In models hierarchy should represent the natural relationships present in the problem domain In a hierarchy all the common features of a set of objects can be accumulated in a superclass This relationship is also known as a generalization specialization relationship since subclasses specialize or extend the more generic information contained in the superclass OO Design 12 OO Design 13 Inheritance There are several types of inheritance Strict inheritance a subclass uses all of the features of its parent class without modification The subclass only adds new attributes or methods Non strict inheritance a subclass may redefine features of the superclass or ignore features of the superclass Strict inheritance supports is a cleanly and has fewer side effects If a subclass redefines a method of the parent it can potentially break the contract that the superclass offers its users OO Design 14 Inheritance Single inheritance a subclass inherits from only one superclass Class hierarchy is a tree Multiple inheritance a class inherits from more than one class Can cause runtime conflicts Repeated inheritance a class inherits from a class but from two separate paths OO Design 15 Inheritance and Polymorphism Inheritance enables polymorphism i e an object can be of different types An object of type B is also an object of type A Hence an object has a static type and a dynamic type Implications on type checking Also brings dynamic binding of operations which allows writing of general code where operations do different things depending on the type OO Design 16 Module Level Concepts Basic modules are classes During OO design a key activity is to specify the classes in the system being built In creating our design we want it to be correct i e cover its requirements But a design should also be good efficient modifiable stable We can evaluate an OO design using three concepts coupling cohesion and open closed principle OO Design 17 Coupling In OO design three types of coupling exists interaction component inheritance OO Design 18 Coupling Interaction coupling occurs when the methods of a class invoke methods of another class this can t be avoided obviously but we want to ensure that an object s public interface is used a method of class A should NOT directly manipulate the attributes of another class B Why OO Design 19 Coupling Component coupling when a class A has variables of another class C A has instance variables of type C A has a method with a parameter of type C A has a method with a local variable of type C When A is coupled with C it is coupled with all subclasses of C as well Component coupling will generally imply the presence of interaction coupling also OO Design 20 Coupling Inheritance coupling two classes are coupled if one is a subclass of the other again can t be avoided inheritance is a useful and desirable feature of OO approaches however a subclass should strive to only add features attributes methods to its superclass as opposed to modifying the features it inherits from its superclass OO Design 21 Cohesion Cohesion is an intramodule concept Focuses on why elements are together Only elements tightly related should exist together in a module class This gives a module a clear abstraction and makes it easier to understand Higher cohesion leads to lower coupling as many otherwise


View Full Document

CU-Boulder CSCI 5828 - Object Oriented Design

Documents in this Course
Drupal

Drupal

31 pages

Deadlock

Deadlock

23 pages

Deadlock

Deadlock

23 pages

Deadlock

Deadlock

22 pages

Load more
Loading Unlocking...
Login

Join to view Object Oriented Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object Oriented Design and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?