Object Oriented System Analysis and Design(INSY2052)
Chapter 2
Understanding the Basics :Object
oriented concepts
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 1
Understanding the basics of object oriented concepts
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 2
Basic Object Oriented Concepts
Inheritance, Encapsulation
Polymorphism, Abstraction
Relations:
Coupling ,Cohesion
Aggregation, Composition
Association, Collaboration
Interfaces,
Components, Patterns
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 3
Inheritance
Inheritance: allows one class of objects to be defined as a special case of a
more general class.
Special cases are subclasses and more general cases are super classes.
Subclass inherits all properties of its super classes and can define its own
unique properties.
Inheritance=Super class + sub class
Use of inheritance: makes our code easy to understand and reduces the lines
of code.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 4
Inheritance
Sometimes called Generalization/specialization concept.
Sub class_super class Generalization
Super class_sub class Specialization
Inheritance is one way we can achieve polymorphism, which is the
ability to treat a set of objects of similar types as the same.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 5
Example: an Inheritance Hierarchy
Vehicle
Automobile Motorcycle Bus
Sedan Sports Car School Bus Luxury Bus
What properties does each vehicle inherit from the types of vehicles
above it in the diagram?
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 6
Encapsulation
Encapsulation: refers to an object hiding its attributes behind its
operations (it seals the attributes in a capsule, with operations on the edge).
Encapsulation means to design, produce, and describe software so that it
can be easily used without knowing the details of how it works.
Provides information hiding by restricting the external visibility of a unit’s
information.
Also known as information hiding.
Hidden attributes are said to be private.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 7
Cont’d…
Users of a class should not be concerned with internal representation
of data members or implementation details of services.
If any of these have changed, users of the class should not be effected.
An analogy:
When you drive a car, you don’t have know the details of how many cylinders
the engine has or how the gasoline and air are mixed and ignited. Instead you
only have to know how to use the controls.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 8
Cont’d…
Use of encapsulation:
It enables the users and programmers to see the system components
according to the privilege they are given.
Separates the behavior from the implementation which makes the program
modular and simple.
Helps to make easily understandable program.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 9
Polymorphism
Polymorphism: is the ability of an object to take many forms. Objects in
different classes may respond differently to messages with the same name.
Polymorphism =poly +morphism
poly -> many, morphism -> forms
Major Components:
Overriding
Overloading
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 10
Example: to show polymorphism
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 11
Cont’d…
Overriding: when a class or method have the same
signature(method name +attributes) with other class or method,
and when that class or method makes a special implementation of
the overridden class or method.
Eg. class Animals {
public static void main(String args[]) {
Animal animal = new Animal();
Cat cat= new Cat();
animal.print();
cat.print(); } public class Cat extends Animals {
void print() { void print() {
System.out.println("Superclass Animals"); System.out.println("Subclass
Cat");}
}}} Out put: Superclass Animals INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 12
Cont’d…
Overloading: when a class or method have the same method
name but different set of parameters or attributes(signature).
Eg.
class oosad{
public static void main(String args[]) {
int output(10);
double output(10.0);}
static void output(int i) {
System.out.println("int i = " + i);}
static void output(double d) { // same name, different parameters
System.out.println("double j = " + j);}
}
Out put will be int i=10
double d=10.0
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 13
Other important terms in OOP
Interfaces
Abstractions
Relationships
Association
Aggregation
Cohesion and coupling
Composition
Generalization….
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 14
Interfaces
Interfaces: provide abstraction meaning you shouldn’t have to know anything
about what is in the implementation in order to use it.
They are collections of abstract classes.
They are not implemented.
High level object oriented concepts
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 15
Abstraction
Abstraction: Is a method of creating abstract classes.
is the identification of the essential characteristics of an item.
It means ignoring irrelevant features, properties, or methods and emphasizing
the relevant ones.
Allows us to create interfaces.
It allows us to represent a complex reality in terms of a simplified model.
Its methods are partially implemented.
Use of using interfaces and abstract classes in system development:
makes our system easy to maintain and debug.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 16
Relations
Relations: No object is an independent. All objects are connected to other
objects:
directly or indirectly
strongly or loosely
Major types of object relations:
Association, Aggregation
Composition, Coupling ,Cohesion
Collaboration, Generalization….
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 17
What is the need of making relations or connections?
By connecting objects, we make them more powerful.
Association
week form of connection between objects or entities.
the objects may be part of a group, or family, of objects but they’re not
completely dependent on each other.
Association: Symbolized by ( ).
Composition: symbolized by filled diamond.
Aggregation: Symbolized by hollow diamond.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 18
What is the need of making relations or connections?
By connecting objects, we make them more powerful.
Aggregation
strong form of connection.
it is the basic form of connection to build up a large system.
It represents a close dependency.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 19
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 20
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 21
Aggregation Composition
Faculty SalesOrder
(team-teaching is
1..* 1
possible)
0..* 1..*
CourseTeaching SalesOrderLineItem
(another: assembly --> part) (another: hand --> finger)
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 22
Cohesion and Coupling
Cohesion and Coupling are degrees of module dependency.
They are under decomposition concept in OO software engineering
Cohesion Cohesion
Coupling
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 23
Coupling
Coupling defn:The degree of interdependence between two or more
components in a system.
Coupling is a measure of the extent of information interchange between
modules.
Reduced coupling results Reduced Complexity
Coupling assesses the interactions between modules
It is important to distinguish kind and strength
kind: A calls B, C inherits from D, etc., directionality
strength: the number of interactions
Coupling is related to cohesion.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 24
Coupling types
Highly coupled
Loosely coupled
Uncoupled
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 25
Highly coupled
Tight coupling implies large dependence on the structure of one module
by another
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 26
Loosely coupled
Loose coupling is the opposite of tight coupling. Modules with loose coupling
are more independent and easier to maintain
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 27
Uncoupled
Uncoupled components exist.
No Dependencies
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 28
Good vs Bad Coupling
Modules that are loosely coupled (or uncoupled) are better than those that
are tightly coupled
Why? Because of the objective of modules to help with human limitations
The more tightly coupled are two modules, the harder it is to think about
them separately, and thus the benefits become more limited
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 29
Cohesion
It indicates how closely the elements or the statements of a module are
associated with each other in the system inside a specific module/subsystem.
Cohesion is a measure of the internal strength of a module.
The more closely the elements of a module are associated with each other, the
higher the cohesion of the module.
Cohesion refers to the number and diversity of tasks that a single unit is
responsible for.
If each unit is responsible for one single logical task, we say it has high cohesion.
Cohesion applies to classes and methods, We aim for high cohesion.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 30
Cohesion
Types:
Coincidental
Logical
Temporal
Sequential
Note: Coupling vs Cohesion: Cohesion is a measure of the internal strength of a
module, while coupling is a measure of the extent of information interchange
between modules.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 31
Cohesion
Coincidental: Occurs when elements are collected into a module simply
because they happen to fall together/concident.
Logical : several logically related functions or data elements are placed in
same component.
occurs when the element of a module are grouped together according to
certain class of activity
The element falls into some general category because they all do the same
kind of thing
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 32
Cont’d…
Temporal: Sometime a component is used to initialize a system or a set
variables.
Such a component performs several functions in sequence ,but the functions
are related by the timing involved, so its cohesion is temporal.
Occurs when the elements of a module are grouped together because they are
related by time
Sequential: If the output from one part of a component is input to the next
part the component has sequential cohesion.
Occurs when a module contains elements that depend on the processing of
previous elements
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 33
Generalization
relationship denoting the inclusion of the behavior described by another
entity.
When we recognize commonality in characteristics and behavior we abstract
these commonalties out – we generalize
Employee
process of forming a superclass.
very week form of association Manager Programmer
project
budgetsControlled
progLanguages
dateAppointed
Project Dept. Strateg
ic
Manager Manager Manager
projects dept responsibilities
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 34
Cont’d…
Relation Strength: Composition >Aggregation>Association>Generalization
Note: The differences between different types of relations is the underlying
semantic strength.
We will see other types of relations in UML in chapter three in class diagrams.
One-to –one
One-to –many
Many-to -many
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 35
Components
A software component is a modular building block for computer software
It is a modular, deployable, and replaceable part of a system that encapsulates
implementation and exposes a set of interfaces
A component may communicates and
collaborates with Other components
and entities outside the boundaries of
the system
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 36
Patterns
Patterns are designs that are used as a guide in doing projects.
In software engineering, a design pattern is a general reusable solution to a
commonly occurring problem in software design.
A design pattern is not a finished design that can be transformed directly into
code.
It is a description or template for how to solve a problem that can be used in
many different situations.
Object-oriented design patterns typically show relationships and interactions
between classes or objects, without specifying the final application classes or
objects that are involved.
Is a common solution to a recurring problem in design
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 37
Patterns
characteristics
Patterns are sort of design
But: patterns transcend/wide ranging/ the “identify classes and associations”
approach to design
Instead: learn to recognize patterns in the problem space and translate to the
solution
Patterns can capture OO design principles within a specific domain
Patterns provide structure to “design”
At a higher level there are Architectural patterns that are larger in scope,
usually describing an overall pattern followed by an entire system.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 38
Patterns
Design Patterns represent a lower level of system structure than “software
architecture”
Goal of design patterns:
Codify good design: Distil and disseminate experience, abstract how to think
about design
Give design structures explicit names: Common vocabulary, Reduced complexity
Capture and preserve design information: Improve documentation
Facilitate restructuring/refactoring: Patterns are interrelated, Additional
flexibility
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 39
Design Patterns goals
Design patterns can speed up the development process by providing tested,
proven development paradigms.
Effective software design requires considering issues that may not become
visible until later in the implementation.
Reusing design patterns helps to prevent subtle issues that can cause major
problems, and it also improves code readability for coders and architects who are
familiar with the patterns.
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 40
End of
chapter two!
INFORMATION SYSTEM-SCHOOL OF INFORMATICS-WSU 41