Object-Oriented Modeling and Design With UML: Chapter 1. Introduction & Chapter 2. Modeling As A Design Technique
Object-Oriented Modeling and Design With UML: Chapter 1. Introduction & Chapter 2. Modeling As A Design Technique
Contents
Introduction Object-oriented (OO) concept OO characteristics OO development OO themes Evidence for usefulness of OO Summary
2005-04-26 2 / 20
Introduction
Object-oriented (OO) approach to software development based on modeling objects from the real world Use the model to build languageindependent design organizing objects OO modeling and design promotes
Better understanding of requirements Cleaner design More maintainable systems
2005-04-26 3 / 20
Object-oriented concept
Object-oriented modeling and design
Using models organized around real-world concepts
Object incorporates data structure and behavior Object-oriented vs. Previous programming
Object-oriented
a collection of discrete object that incorporate both data structure and behavior
2005-04-26
Previous programming
data structure and behavior is loosely connected
4 / 20
OO characteristics (1/4)
Identity
Data is quantized into discrete, distinguishable entities called objects Each object has is own inherent identity
Two objects are distinct even if all their attribute values are identical
2005-04-26
5 / 20
OO characteristics (2/4)
Classification
Objects with the same data structure (attributes) and behavior (operations) are grouped into a class Abstraction that describes properties important to an application and ignores the rest
Polygon objects abstract into Polygon class
Attributes vertices border color fill color 2005-04-26
OO characteristics (3/4)
Inheritance
Sharing of attributes and operations (features) among classes based on a hierarchical relationship
Super class has general information that subclasses refine and elaborate Each subclass incorporates, or inherits, all the features that subclass and adds its own unique features
2005-04-26
7 / 20
OO characteristics (4/4)
Polymorphism
Same operation behaves differently for different classes
Ex) + operation
Integer summation Float summation String summation
OO operator is polymorphic
Have more than one method implementing it
Each for a different class of object
2005-04-26
8 / 20
OO development (1/6)
Essence of OO development
Identification and organization of application concepts
OO development (2/6)
OO Methodology
Methodology= building a model + adding details during design Following stages
System conception Analysis System design Class design Implementation
2005-04-26
10 / 20
OO development (3/6)
Modeling
Abstraction for the purpose of understanding before building it Purpose
Testing a physical entity before building it Communication with customers Visualization Reduction of complexity
2005-04-26
11 / 20
OO development (4/6)
Three models
Class model
Function
Describes the static structure of objects in a system Provides context for state and interaction model
Goal
Capture important concepts to an application from the real world
Representation
Class diagrams Generalization, aggregation
2005-04-26
12 / 20
OO development (5/6)
Three models (Contd)
State model
Function
Describes objects time and sequencing of operation
Goal
Capture control of system aspect that describes the sequences of operations that occur
Representation
State diagrams
2005-04-26
13 / 20
OO development (6/6)
Three models (Contd)
Interaction model
Function
Describes interactions between objects Individual objects collaborate to achieve the behavior of the whole system
Goal
Exchanges between objects and provides a holistic overview of the operation of a system
Representation
Use cases, sequence diagrams, activity diagrams
2005-04-26
14 / 20
OO themes (1/4)
Abstraction
Definition
Selective examination of certain aspects of a problem
Goal
Isolate important aspects, suppress unimportant aspects
2005-04-26
15 / 20
OO themes (2/4)
Encapsulation
Separates the external aspects of an object from internal implementation Data structure and behavior is encapsulated in a single entity Ensuring reliability and maintainability
Information exchange is done by public interface among objects Change internal data structure does not affect other objects
2005-04-26
16 / 20
OO themes (3/4)
Combining data and behavior
Data structure hierarchy matches the operation inheritance hierarchy
Is replaced by
class hierarchy
procedure hierarchy
Old approach
2005-04-26
OO approach
17 / 20
OO themes (4/4)
Sharing
No redundancy Reusability
Synergy
Identity, classification, polymorphism, inheritance
Be clearer, more general and robust
2005-04-26
18 / 20
Advantage
Reusability Effective maintenance
Disadvantage
Not applicable in performance critical rather than data
2005-04-26 19 / 20
Summary
Object-oriented development
Low cost in system maintenance Adequate delivery on users requests
Flexible and elastic in frequent system change
2005-04-26
20 / 20
Inheritance Example 1
class Shape{ int x; int y; void setOrigin(int x, int y){ this.x=x; this.y=y; } } class Rectangle{ int x; int y; int width, height; void setOrigin(int x, int y){ this.x=x; this.y=y; } void setSize(int w, int h){ width=w; height=h; } } class Circle{ int x; int y; int radius; void setOrigin(int x, int y){ this.x=x; this.y=y; } void setRadius(int r){ radius=r; } }
2005-04-26
21 / 20
Inheritance Example 1
class Rectangle extends Shape{ int width; int height; void setSize(int w, int h){ width=w; height=h; } } class Circle extends Shape{ int radius; void setRadius(int r); radius=r; } }
2005-04-26
22 / 20
Inheritance Example 2
class A { int x; void f() { x = x+1; } } class B extends A { int y; void g() { y = y*2; } }