SAD - Ch1 - Introduction To Object-Oriented Development
SAD - Ch1 - Introduction To Object-Oriented Development
1
System analysis and design
•Chapter 1
2
System analysis and design
Functional/procedural approach
• Based on specified functions of the system
• A system consists of several functions
• Decomposition of functions into sub-functions
• A system consists of sub-systems
• A sub-system is divided into smaller subsystems System
Function 1 Function 2
Functional approach
• Advantages
• Easy to apply
• Work well when data are simple
• Help to reduce complexity
• Obtain expected results
• Disadvantages
• Functions are separated from data
• Structure of the system is defined based on the functions, therefore a change of functions will
cause difficulties in change of the structure
• The system is weakly open
• Difficult to re-use
• An significant maintenant cost
5
System analysis and design
Object-oriented approach
Object 3
Object 1
Object 4
6
System analysis and design
Object-oriented approach
• Advantages
• Very close to the real world
• Easy to reuse
• Hide information (encapsulation)
• Lower development cost (inheritance)
• Suitable for complex systems
7
System analysis and design
Objects
• Object is the concept describing an entity in the real world
• There are relationships between the objects
• Example
• The Student “Micheal” is an object
• The Student can’t be an object !
• Object = state + behavior + identity
• State (data) describes the characteristics of an object at a given time, and is saved in the
variables
• The behavior is expressed by the functions of the object
• Each object has a unique identity
identity
• Example aRectangle aPoint
length = 4 x=0 state
width = 2 y=0
origin = aPoint move() behavior
area()
8
System analysis and design
Objects
9
System analysis and design
Objects
• Links
• Between objects, there may be links
• Example
studies at
Michael the university of Danang
10
System analysis and design
Classes
• A class is an abstract description of a set of objects having
• similar properties
• common behavior
• common relationship with other objects
• Class is an abstraction
• Abstraction: search for common aspects and omit the differences
11
System analysis and design
Class
• Relationship
• There may be relationship between classes
• A relationship between classes is the set of links between their objects
Studies at
Student University
• Class/Object
• An object is an instance of a class
• A value is an instance of an attribute
• A link between objects is an instance of the relationship between classes
12
System analysis and design
Classes
13
System analysis and design
Encapsulation
Class
attributes
methods
14
System analysis and design
Encapsulation
• Advantages
• Hide the information
• Restrict access to the information from the exterior
• Avoid the global changes in the whole system: the internal implementation can be
modified without affecting the external users
• Facilitate the modularity
• Easy to reuse
• Easy to maintain
15
System analysis and design
Inheritance
• Inheritance allows the reuse of the state and the behavior of a class by other classes
• A class is derived from one or more classes by sharing attributes and methods
• Subclass inherits attributes and methods of parent-class
• Generalisation / Specialisation
• Generalisation: common attributes of sub-classes are used to construct the parent-class
• Specialisation: sub-classes are constructed from the parent-class by adding other
attributes that are unique to them
Parent-class
specialisation
generalisation
Sub-class
16
System analysis and design
Inheritance
• Single inheritance: a sub-class inherits from only one parent-class
• Multiple inheritance: a sub-class inherits from multiple parent-classes
Polygon
Rectangle Lozenge
multiple inheritance
Square
• What is the difficulty of multiple inheritance?
17
System analysis and design
Inheritance
• Advantages
• Organisation of classes
• classes are organised hierarchically
• facilitation of the management of classes
• Construction of classes
• sub-classes are constructed from parent-classes
• Reduction of development cost by avoiding to re-write the code Polygon
• Allowing to apply easily the technique of polymorphism
Rectangle Lozenge
multiple inheritance
Square
18
System analysis and design
Polymorphism
• Polymorphism of methods
• Different methods are capable of answering to a request
• Methods having the same name are defined differently (different behaviors) in different classes
• Sub-classes inherit the specification of methods from parent-class and these methods can be re-
defined appropriately
• Reducing the use of conditional statements (e.g., if-else, switch)
• Procedural approach versus Object-oriented approach
Account
credit
main
debit
CurrentAccount SavingAccount
Calculate costs Calculate costs
calculate costs calculate interests Calculate interests Calculate interests
if current account if current account
… …
if saving account if saving account
… …
else … else …
19
System analysis and design
• The method to be executed by an object depends on the class of the object: dynamic linking
• The dynamic linking is necessary when
• A variable refers to an object whose class of membership is part of an inheritance tree
• Several methods exist for the same message (name) in the inheritance tree
(polymorphism)
int calculateCost(Account accounts)
{
int s = 0;
Account for (int i = 0; i < accounts.length; i++)
calculateCosts() s = s + accounts[i]->calculateCosts();
calculateInterests() return s;
}
void main()
CurrentAccount SavingAccount {
calculateCosts() calculateCosts() Account accounts = new Account[2];
calculateInterests() calculateInterests() accounts[0] = new CurrentAccount();
accounts[1] = new SavingAccount();
int s = calculateCost(accounts);
…
}
20
System analysis and design
Ellipse Polygon
area() area()
perimeter() perimeter()
21
System analysis and design
Ellipse Polygon
area() area()
perimeter() parimeter()