You are on page 1of 49

Chapter 1

Understanding the Basics :Object


Oriented concepts
1.1 Object oriented concepts from
structured point of view
The four Basic OO concepts in structural
terminology
1. Class –is a software abstraction of
objects.
• It is a template from which objects are
created.
• It is a set of objects that share the same
attribute and behavior
• E.g. A class is equivalent to table in a database
concepts
2. Object – is a person, place,
thing ,event ,concept , screen , or report
E.g. It can be thought as a record in a table.
3. Attribute- Is equivalent to a data element in a
record .
• From programming point view ,It also makes sense
to think of an attribute as a local variable that is
applicable only to a single object.
4. Method – A method can be thought of as a
function or procedure.
• A method access and modify attributes of an
object.
• Some methods return a value ( like a function)
other methods do not like a procedure .
• Method- Small Talk
• Function-C++
• Operation- Java -UML
Class name
Attribute Class Name
Method

Student
Name
Phone Number
Student Number Student
Enroll in Seminar
Drop seminar
Pay tuitions
Request Transcript
• Class names are typically nouns
• Class names are usually singular
Instantiate- when we create an object we
say we instantiate it from the class student
1.2. Inheritance
• Inheritance –as a child inherits the properties of
his parents ,a new class can derive its properties
from another existing class.
• Thus it becomes the derived class of its parent
class, which is the base class
• The derived class inherits all the properties of the
base class
• The degree of encapsulation of the base class
applies equally to the derived class
• More properties may be added to the derived class
Professor
Inheritance about bank account
• A person class is a super class
• Student and professor class are sub
classes
• Inheritance is represented by “is like “ or
“is a” relationship
abstract class.doc
Car
Airplane
Make
MaxAlttitude
MaxFuel
MaxFuel
MaxNoPassamger
MaxNoPassamgers
s
MaxSpeed
MaxSpeed
NoEngines
Model
Accelerate
Accelerate
Bank
Decelerate
Climb
turn
Decelerate
Decend
• Multiple inheritance is occurred
when a class inherits from more than one
class
• Multiple inheritance is supported by C+
+,but not many languages like Java,
Smalltalk, object c,
• Single Inheritance - when a class inherits
from only one class
Abstract and Concrete classes
• Abstract classes are introduced into a model to
implement behaviors common to several classes.
• The main difference between abstract classes
and concrete classes is that objects are
instantiated (created) from concrete classes but
not in abstract classes.
E.g. in the previous problem domain, we have
Airplanes and Cars, but you do not have any
thing that is just a vehicle( if it is not an Airplane
or a car, we are not interested in it).
This means we can instantiate airplane and car
objects but will never create vehicle objects.
• Applying the concept of inheritance in the
class diagram
E.g. in the previous problem domain, we
have Airplanes and Cars, but you do not
have any thing that is just a vehicle( if it is
not an Airplane or a car, we are not
interested in it).
This means we can instantiate airplane and
car objects but will never create vehicle
objects.
1.3 Abstraction, encapsulation and
information hiding
• The world is a complicated place
• To deal with this complexity, we form
generalizations or abstractions of the things
in it.
• For example consider the abstraction of a
person,
• From the point of view of a university, it
needs to know the person’s name, address,
phone number, Social security number ,and
educational background
• From the point of view of a police, they
need to know the person’s name, address
phone number, weight ,height hair color,
eye color and so on.
• Abstraction is an analysis issue that deals
with what a class knows or does.
• The abstraction should include the
features, attributes and methods that are
interested to your application and ignore
the rest.
• Encapsulation-The grouping of related
concepts into one item such as a class or
a component
• It deals with the issues of how you
intended to modularize the features of a
system
• In the object oriented world you
modularize, we modularize systems into
classes, which intern are modularized into
methods and attributes
• Budling of attributes and methods in a
single unit – e.g. class in java
• We say that we encapsulate behavior into a
class or we encapsulate functionality into a
class.
• Encapsulation is a design issue that deals
with how functionality is compartmentalized
with in a system.
• One need not know how some thing is
implemented to be able to use it .
• Information hiding – the restriction of
external access to the rest of the world
• If one class wants information about
another class it should have to ask for it
instead of taking it.
• Private/protected attributes - implementation
1.4 Associations
• In the real world, objects have
relationships ,associations, other objects. The
relationship between objects are important
because they help us to define how they interact
with each other. For example:
• Students TAKE courses
• Professors TEACH courses,
• Criminals ROB banks
• Take, teach and rob are verbs that define
associations between objects.
• A student takes one or more seminars
• A seminar is taken by zero or more
students
• A student as teaching assistant, may
assist in one or more seminars
• A seminar may have one student who acts
as a teaching assistant
• A seminar is a section of one course
• A course has a zero or more sections
• An employee holds one position
• A position may be held by one employee
(some positions go unified)
• An employee may be managed by one
other employee ,his or her manager (the
company president is the only one without
a manager )
• An employee manages zero or more
employees( some employees don't have
any staff members)
Cardinality A Cardinality B
Label
Class A Class
Role A Role B
• Cardinality- Represents the concept “ how
many ?” in association
• Optionally-Represents the concept “ do
you need to have it ?” in associations
• Multiplicity- The UML combines the
concepts of cardinality and optionality into
the single concept of multiplicity
UML multiplicity indicators
• Bidirectional association -An association
that can be traversed in both directions
• Recursive association – an association in
which the objects involved in it are
instances of the same class.
• E.g. An Employee manages an employee
• Role- The context that an object takes
within an association.
• E.g. An employee takes the role of a
manager
3.5 Aggregation
• An object is part of an other object
• Aggregation models “is part of” association.
• Example of aggregation
• An airplane is made up of a fuselage,
wings, engines, landing gear, flaps, and so
on.
• A team consists of two or more employees
• Aggregation models “ is part of “
associations
• Sometimes objects are made up of other
objects.
• If we are interested in keeping track of the
parts, we model them.
A course is part of a program
1.5.1 Composition
• A strong form of aggregation in which the
“whole” is completely responsible for parts
and each “part” object is only associated
with the one “whole” object.
• E.g. A component is part of the product
1.6 Collaboration
• In CRC modeling we will see that classes
often need to work together to fulfill their
responsibilities.
• Actually, it is the objects, the instances of
the classes, that are working together.
• Collaboration occurs When one object
asks another for information or to do
something.
• For example an air plane collaborates with
its engines to fly.
• For the plane to go faster, the engines
must go faster
• When the plane needs to go down, the
engines must go down.
1.6.1 Messages
• Objects collaborate with one another by
sending each other messages .
• A message is either a request to do
something or a request to information.
• Messages are modeled in UML sequence
diagrams and UML collaboration
diagrams. (covered in chapter 5)
1.7 Persistence
• Persistence focuses on the issue of how to save,
retrieve, and delete objects to/from permanent
storage.
• To make an object persistent ,you must save the
values of its attributes to permanent storage
(such as relational database or a file ) as well as
any information needed to maintain the
relationships (aggregation, inheritance and
association) with which it is involved.
• From a development point of view two types of
objects exist.
• Persistent objects that stick around and
• transient objects that do not.
• For example - customer is a persistent
object ,that you save customer objects into
some sort of permanent storage. So you can
work with them in the future.
• However a customer editing screen is a transient
object. i.e. the application creates the customer
editing screen object, displays it ,and then gets
rid of it once the user is done editing the data for
the customer with whom she/he is dealing
1. Business/domain classes are usually
persistent –you need to store attributes
and associations
2. UI classes are usually transitory –
screens and reports.
1.8. Coupling
• Coupling is a measure of how much two
items such as classes or methods are
interrelated. when one class depends on
another class we say that they are coupled
• When one class interacts with an other
class, but does not know any of the
implementation details of the other class
we say they are loosely coupled
• When one class directly accesses the data
attributes of the other, we say they are
highly coupled.
• Tips of coupling
– Avoid high coupling if possible
– Document high coupling thoroughly.
1.9. cohesion
• The degree of relatedness with in an
encapsulated object (such as a class or a
component .)
• A good measure of cohesiveness of some
thing is how long it takes to describe in
one sentence. The longer it takes the less
cohesive it likely is.
• A method is highly cohesive if it does one
thing and one thing only.
• E.g. “enroll in seminar “,”drop seminar”
each one of them does one thing and one
thing only
• But one can write a function by combining
the two “change seminar status” this is
more complex to understand and probably
difficult for maintenance
• A highly cohesive class represents one
type of object and one type of object only.
• E.g. in the university system,
• Model professor, instead of employee
which may have several sub classes like
professor, secretary, registrar, janitor
1.10. Polymorphism
• Polymorphism- different objects can
respond to the same message in different
ways.
• enables objects to interact with one
another without knowing their exact type.
• Polymorphism enables objects to
collaborate with other objects without
knowing their type in advance.
• E.g. for the massage “draw”, different
objects respond differently.
• The artist object responds to the message
by drawing a picture.
• The gun fighter responded by drawing his
gun
• The player responded - no winner (finish
equal)

You might also like