Object Oriented Concepts

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Recap of the last session…

Object Oriented
Concepts
Session outline

• Object model benefits


• Object oriented vs structured approach
• Class and object
• Method and attribute
• Encapsulation
• Abstraction
• Relationships
• Inheritance
• Polymorphism
• Coupling and cohesion
Object Oriented Systems
• Structured analysis treats processes and data as separate
components,
• object oriented analysis combines data and the processes
that act on the data into things called objects
• Using an O-O programming language, a programmer then
writes the code
that creates the objects
• An object is a member of a class, which is a collection of
similar objects
Benefits of Object model
• The benefits of using the object model are
• It helps in faster development of software
• It is easy to maintain. Suppose a module develops an error, then a
programmer can fix that particular module, while the other parts of the
software are still up and running
• It supports relatively hassle-free upgrades
• It enables reuse of objects, designs, and functions
• It reduces development risks, particularly in integration of complex systems
Object oriented Vs Structured
• Objects are easier for people to understand
• Specialists can communicate better – different people
must communicate
• Programmer
• Senior programmer
• Designer and
• Analyst
• Data and processes are not artificially separated
• Code can be reused more easily:
Objects and classes
• An object is a thing, an entity, a noun, something you can pick up or kick, anything
you can imagine that has its own identity
• Object is the basic unit of object orientation

• Examples from the real world include a car, a person, a house, a table, a dog, a
patient…
• All objects have attributes: for example, a car has a manufacturer, a model
number, a color and a price
• Objects also have operations to perform: a car can move from one place to
another and a dog can bark.

• We’re not trying to simulate the real world, that would be far too difficult. we’re
simply trying to make sure that our software is influenced by real-world concepts,
so that it is easier to produce and easier to change
Depicting objects

• A single object is simply an instance of a


class
• An individual object is a concrete entity
that performs some role in the overall
system
• The class captures the structure and
behavior common to all related objects
Class
• A class holds characteristics common to a group of
objects
• A class is an abstraction of objects while an object is
instance of a class

• Examples of a class
• A factory manufactures objects according to some blueprint.
• A set specifies what features its member objects will have.
• A template allows us to produce any number of objects of a
given shape.
Attributes
• descriptive pieces of information about things or
objects
• For example, a customer has a name, a phone number,
a credit limit, and so on
What is an Attribute?
Object
Class

Attribute Attribute Value


:CourseOffering
number = 101
CourseOffering startTime = 9:00
number endTime = 11:00
startTime
endTime

:CourseOffering
number = 104
startTime = 11:00
endTime = 12:00
Method/operation
• Is some action that one object performs upon another in order to
elicit a reaction
• For example a car moves, stops, turns…
What is an Operation?

CourseOffering
Class
addStudent
deleteStudent
getStartTime
Operation getEndTime
• Identify objects and classes from the
student information system.
Encapsulation
• Encapsulation refers to an object hiding its attributes behind its operations
• Hidden attributes are said to be private
• If we get direct access to attributes it would be much harder to change the internal
representation of the object in the future, because we’d have to find all the pieces of
code that access the attributes directly and change those too.
• Without encapsulation we would lose simplicity and locality.

• If you wanted to borrow money from a colleague to buy food


in the staff lounge, you wouldn’t grab their wallet and look
through it to see if they had enough cash. Instead, you
would ask them whether they could lend you some money
and they would look in their own wallet
Abstraction
• An abstraction denotes the essential characteristics of an object
• Abstraction is about focusing on only important details according to the
perspective of the viewer
• For example- a person is an employee when he works for the bank
a patient when he gets ill
a student when he is learning
• So an abstraction would mean only focusing on the relevant details from our
point of view
i.e. if we are modelling for a bank information system- the shoe size of the
person is irrelevant …
Association and aggregation
• No object is an island. All objects are connected to other objects,
directly or indirectly, strongly or loosely. +
• When we’re modeling with objects, we can connect them in two
principal ways: association or aggregation
Association
• It’s sometimes hard to spot the difference between the two
• Association is a weak form of connection: the objects may be
part of a group, or family, of objects but they’re not completely
dependent on each other.
• Degree of an Association
Degree of an association denotes the number of classes
involved in a connection. Degree may be unary, binary, or
ternary.
A unary relationship connects objects of the same class.
A binary relationship connects objects of two classes.
A ternary and n-ary relationship connect objects of three or
more classes respectively
Aggregation

• Aggregation means putting objects together to make a bigger


object
• Aggregations usually form a part–whole hierarchy, implies
close dependency
• Aggregation is referred as a “part–of” or “has– a” relationship

• As suggested, the distinction between association and aggregation


can be subtle. The ‘What happens if you remove one of the objects?’
test can be helpful, but it doesn’t always solve the problem: hard
thinking and experience are often needed.
Activity
• Classify as association and aggregation
• Pages in a book
• Notes in a symphony
• Books on a bookshelf
• Television or computer
Inheritance
• Inheritance is the mechanism that permits new classes to
be created out of existing classes by extending and
refining its capabilities.
• Inheritance allows us to specify that a class gets some of
its characteristics from a parent class and then adds
unique features of its own
• Inheritance defines an “is – a” relationship
Generalizations and Specializations
• Represent a hierarchy of relationships between classes, where
subclasses inherit from super-classes.
Generalization
• The common characteristics of classes are combined to form a class
in a higher level of hierarchy, i.e., subclasses are combined to form a
generalized super-class- represents an “is-a ” relationship
Specialization
• Specialization is the reverse process of generalization
• the distinguishing features of groups of objects are used to form
specialized classes from existing classes
• It can be said that the subclasses are the specialized versions of the
super-class.
• Parent/child: LandVehicle is the parent of Train; Train is a child of
LandVehicle.
• Superclass/subclass: LandVehicle is the superclass of Train; Train is a
subclass of LandVehicle.
• Base/derived: LandVehicle is the base from which Train is derived
Polymorphism
• Polymorphism is originally a Greek word that means the ability to
take multiple forms
• object-oriented paradigm, polymorphism implies using operations in
different ways, depending upon the instance they are operating upon

• Example - consider two classes, Circle and Square, each with a


method findArea().
• Polymorphism is particularly effective while implementing
inheritance
Coupling and cohesion

• Coupling – concerns relationships between classes

• Cohesion – concerns relationships within a classes


• The goal is to have loosely coupled classes with high internal
cohesion

• The more one class has to “know” about another class, the higher is the
coupling between them

• Proper encapsulation reduces coupling

• Both concepts are derived from the structured approach


Construct your objects and identify
degree of relationships.
The End .

You might also like