0% found this document useful (0 votes)
51 views

SAD - Ch1 - Introduction To Object-Oriented Development

This document discusses systems analysis and design using object-oriented approaches. It introduces object-oriented concepts including objects, classes, encapsulation, inheritance, and polymorphism. It compares functional and object-oriented approaches, describing how object-oriented development models systems as collections of communicating objects rather than separate functions. The key concepts of objects, classes, encapsulation, and inheritance are then explained in more detail.

Uploaded by

Le Nhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

SAD - Ch1 - Introduction To Object-Oriented Development

This document discusses systems analysis and design using object-oriented approaches. It introduces object-oriented concepts including objects, classes, encapsulation, inheritance, and polymorphism. It compares functional and object-oriented approaches, describing how object-oriented development models systems as collections of communicating objects rather than separate functions. The key concepts of objects, classes, encapsulation, and inheritance are then explained in more detail.

Uploaded by

Le Nhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

SYSTEMS

ANALYSIS AND DESIGN


Nguyen Thanh Binh, Nguyen Quang Vu, Le Viet Truong, Nguyen Thi
Hanh, Vo Van Luong, Le Thi Bich Tra
Faculty of Computer Science
Introduction to object-oriented development
• Functional approach
• Object-oriented approach
• Object-oriented concepts
• Objects
• Classes
• Encapsulation
• Inheritance
• Polymorphism
• Abstraction
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

Function 1.1 Function 1.2 Function 2.1 Function 2.2

• Functions communicate using shared data or transfer of parameters


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

4
Object-oriented approach

• The solution of a problem is organized around the concept of objects


• The object is an abstraction of data also containing functions
• A system consists of objects and relationships between them
• Objects communicated by exchanging messages to perform a task
• No global variables
• Encapsulation
System Object 2
• Inheritance

Object 3
Object 1

Object 4

5
Object-oriented approach

• Advantages
• Very close to the real world
• Easy to reuse
• Hide information (encapsulation)
• Lower development cost (inheritance)
• Suitable for complex systems

• Functional approach v.s. object-oriented approach


• Functional approach
• System = algorithms + data structures
• Object-oriented approaches
• System = Σ objects
• Object = algorithms + data structures

6
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
aRectangle aPoint
• Example
length = 2 x=0 state
width = 4 y=0
origin = aPoint move() behavior

area()
7
Objects

• State = Set of attributes


• An attribute describes one property of the object
• At every moment, an attribute has a value in a specific set of attributes area
• Example
• The car has properties: color, length, width, weight, number of kilometres, …
• A Renault 207 weighs 1300 pounds, it is red, …
• behavior = Set of functions
• A function/method is the ability of the object to perform a task
• The behavior depends on state
• Example: A car can start the engine then run, …

8
Objects

• Links
• Between objects, there may be links
• Example
studies at
Michael the university of Danang

• Communication between objects


• Send messages
registers()
Michael the university of Danang
• Message types
• constructor
• destructor
• getter
• setter
• others

9
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

• Reduce the complexity

10
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

11
Classes

• Example: Class / Object


point1
x=5
Point y=5
x : float move()
y : float
move() point2
x=0
Rectangle y=0
length : float move()
width : float aRectangle
origin: Point length = 2
area() width = 4
origin = point2
area()

12
Encapsulation

• Data + Processing of data = Object


• Attributes + Methods = Class
Class

attributes

methods

• The state of object is encapsulated by a set of attributes


• The behavior is encapsulated by a set of methods
• Users of an object know the messages that the object can receive (public methods)
• The implementations of methods are hidden from external users

13
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

14
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

15
Inheritance

• Single inheritance: a sub-class inherits from only one parent-class


• Multiple inheritance: a sub-class inherits from multiple parent-classes

• Example : a tree of inheritance

Polygon

single inheritance Parallelogram Triangle

Rectangle Lozenge

multiple inheritance
Square
• What is the difficulty of multiple inheritance?

16
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
• Allowing to apply easily the technique of polymorphism Polygon

single inheritance Parallelogram Triangle

Rectangle Lozenge

multiple inheritance
Square
17
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
main credit
debit

execute the transaction

CurrentAccount SavingAccount
calculate costs calculate interests Calculate costs Calculate costs
if current account if current account Calculate interests Calculate interests
… …
if saving account if saving account
… …
else … else …

18
Polymorphism: dynamic linking

• 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);

}

19
Abstraction: abstract class
• An abstract class
• indicates the common characteristics of the sub-classes
• can’t have instances/objects
• A concrete class
• contains a complete characterization of real-world objects
• is expected to have instances/objects
Figure
area() Abstract class
perimeter()

Ellipse Polygon
area() area()
perimeter() perimeter()

Circle Parallelogram Triangle


area() area() area()
perimeter() perimeter() perimeter() 20
Abstraction: abstract method
• A method should be defined at the highest possible abstraction level
• At this level, the method can be abstract (i.e., no implementation)
• In this case, the class is also abstract
• If a class has an abstract method, at least one of its subclasses must implement this method
• All the methods of a class at the bottom of the inheritance tree must be concrete
Figure
area() Abstract Methods
perimeter()

Ellipse Polygon
area() area()
perimeter() parimeter()

Circle Parallelogram Triangle


area() area() area()
perimeter() perimeter() perimeter() 21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy