0% found this document useful (0 votes)
37 views29 pages

OOAD Self

Uploaded by

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

OOAD Self

Uploaded by

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

Introduction OBJECT MODEL (Cont.

)
Object Oriented Analysis Polymorphism
Generalization and Specialization
Object Oriented Design Links and Association
Object Oriented Programming Aggregation or Composition
Benefits of Object Model

OBJECT MODEL
Objects
Classes
Encapsulation and Data Hiding
Message Passing
Inheritance
• OOAD Introduction:-

• Object-Oriented Analysis and Design (OOAD) is a method used in software development


where you think of the parts of your software as real-world objects, like cars or bank
accounts. You start by identifying these objects and figuring out how they interact with
each other.
• Each object has its own properties (attributes) and actions (methods), similar to how a
car has a color and can drive. You then create blueprints (classes) for these objects to
define their properties and actions. This approach helps in organizing the software in a
clear, manageable way, making it easier to build and understand.
• Object Oriented Analysis:-

• Object-Oriented Analysis (OOA) is a way to understand and plan software


by focusing on the objects involved in the system. Here’s a simpler
breakdown:

• Purpose: OOA helps identify what the software needs to do and creates a
detailed plan using objects, which are like parts of the software that
interact with each other.
• Object Focus: Unlike other methods that separately consider what the
software does (functions) and the data it uses, OOA combines these
aspects into objects. Each object includes both data and actions.
• Real-World Modeling: Objects in OOA represent real-world things that
the system deals with, like a bank account or a customer.
• Main Steps in OOA:

• Identifying Objects:
• Finding out the key parts (objects) that will be in the software.

• Organizing Objects:
• Creating diagrams that show how these objects are related to each other.

• Defining Attributes:
• Figuring out the details (attributes) that each object will have.

• Defining Behavior:
• Deciding what actions (methods) each object can perform.

• Describing Interactions: Explaining how the objects will work together.


Object Oriented Design :

OOD is about creating a detailed plan for building the software by specifying
how the system's objects will work together, using the concepts and ideas
developed during the analysis phase.

In Object-Oriented Design (OOD), we take the general ideas from the planning phase
and turn them into specific classes and technologies for building the software. We
figure out the rules and design the ways that different parts of the software will
interact. The end result is a detailed plan that shows exactly how to build the system
using the chosen technologies.
• Implementation Details Include:

• Restructuring Class Data: Adjusting the data in the classes if needed.

• Implementing Methods: Defining how the internal data structures and


algorithms will work.

• Implementing Control: Setting up how the system will manage and


control processes.

• Implementing Associations: Defining how objects will be linked and


interact with each other.
• What is Object-Oriented Programming (OOP)?
• Object-Oriented Programming (OOP) is a way of writing software where
programs are made up of objects. These objects have both data and methods
(actions) and are designed to make the code more modular and reusable.
Objects are instances of classes, and they interact with each other to create
applications.

• Key Features of OOP


• Bottom-Up Design: Programs are designed from the bottom up, focusing on
building objects first.
• Organized Around Objects: Code is organized around objects grouped into
classes, focusing on data with methods to work on the data.
• Interaction and Reusability: Objects interact with each other through
functions, and new classes can be created by adding features to existing ones.
• Some examples of object-oriented programming languages are C++, Java,
Smalltalk, Delphi, C#, Perl, Python, Ruby, and PHP

• Grady Boch Defines OOP :-


• Grady Booch defined OOP as a way to implement programs as collections
of interacting objects, where each object is an instance of a class, and
classes are organized in a hierarchy connected through inheritance.
Object Model (Lec 2)

• Objects
• Definition: An object is something from the real world, like a person or a car,
or it can be a concept, like a project or a process. It has three main parts:

• Identity: What makes it different from other objects.


• State: Its properties and the values of those properties.
• Behavior: The actions it can perform.
• Example: Think of a car. It has an identity (its license plate number), state
(color, make, model), and behavior (drive, stop, honk).
• Classes
• Definition: A class is like a blueprint for creating objects that share similar
characteristics and behaviors. It describes what objects of that type will look
like and what they can do.
• Example: Imagine a class called "Animal." It defines the common attributes
(like legs, eyes) and behaviors (like walk, eat) that all animals have. From this
class, you can create objects like "Dog" or "Cat.“

• Combine Example :
•Imagine a class called "Circle" that describes circles in a 2D space.
•Each circle object you create from this class will have attributes like x-coordinate,
• y-coordinate, and radius.
•You can perform operations like finding the area or circumference of the circle,
• or scaling it up or down.
• Attributes:
• x-coordinate: Position on the horizontal axis.
• y-coordinate: Position on the vertical axis.
• Radius (r): Size of the circle.

• Operations (Methods):
• findArea: Calculate the area of the circle.
• findCircumference: Calculate the circumference of the circle.
• scale: Increase or decrease the size of the circle
Encapsulation And Data Hiding:

• Encapsulation
• Definition: Encapsulation is like putting a box around both the data
(attributes) and the actions (methods) that operate on that data within a
class. It ensures that these are kept together inside the class and cannot be
directly accessed from outside.
• Explanation: Imagine you have a recipe box (class) that contains ingredients
(attributes) and cooking instructions (methods). Encapsulation ensures that
these ingredients and instructions are safely stored together inside the box.
You can't just grab the ingredients or instructions from outside; you have to
interact with the box to access them.
• Data Hiding:

• Definition: Data hiding is a part of encapsulation. It means that the inner


details of a class, like its data attributes, are kept private and can only be
accessed or modified through designated methods.
• Explanation: Think of a locked diary (class) where you write your
thoughts (data attributes). The lock (methods) ensures that only you can
access and modify the contents of the diary. Others can't see what's
written inside unless you choose to share it. Data hiding protects the
privacy of your thoughts and prevents unauthorized access.
• Example: Bank Account Class with Encapsulation and Data Hiding

• Attributes:
• Account Number
• Balance
• Owner's Name

• Methods:
• Deposit: Add money to the account.
• Withdraw: Take money out of the account.
• Check Balance: See how much money is in the account.
• Explanation:
• Imagine a class called "BankAccount" with attributes account number,
balance, and owner's name.
• Encapsulation ensures that these attributes are kept together inside the
class.
• Data hiding ensures that these attributes cannot be accessed directly from
outside the class.
• Instead, methods like Deposit and Withdraw are provided to safely interact
with and modify the account balance.
Message Psassing:
• In any application, different objects need to work together smoothly. They do
this by sending messages to each other. Imagine two objects, let's call them
obj1 and obj2. If obj1 wants obj2 to do something, it sends a message to obj2
asking it to perform one of its actions.

• Here are some key points about message passing:


• Unidirectional: When obj1 sends a message to obj2, it's usually a one-way
communication. Obj1 tells obj2 to do something, but obj2 doesn't necessarily
send a message back to obj1.
• All Interactions: Message passing is how all interactions happen between
objects. It's the way they communicate and collaborate.
• Invoking Methods: When obj1 sends a message to obj2, it's essentially
asking obj2 to run one of its methods (actions).

• Across Processes: Objects in different parts of the application or even in


different processes can still communicate through message passing.
Inheritence:
• Inheritance is a programming concept that allows a new class to be created
based on an existing class. The new class, called a "child class" or "derived
class," inherits properties and behaviors from the existing class, known as the
"parent class" or "base class."
• Explanation:
• In simpler terms, inheritance is like having a blueprint for building things,
where you can reuse parts of the blueprint to create new things. The existing
blueprint (parent class) already has some features and instructions on how to
build something. When you want to build something similar but with some
differences, you don't have to start from scratch. Instead, you can use the
existing blueprint as a starting point and add or modify things to create a
new blueprint (child class).
• Example:
• Let's consider a simple example using animals:
• We have a parent class called "Animal" that defines basic attributes and
behaviors common to all animals, such as "name" and "eat()." This class
serves as our blueprint.
• Now, we want to create specific types of animals, like "Dog" and "Cat."
Instead of defining all attributes and behaviors for each type from scratch, we
can create child classes "Dog" and "Cat" that inherit from the "Animal" class.
• The "Dog" class inherits attributes like "name" and behaviors like "eat()" from
the "Animal" class. Additionally, we can add specific attributes and behaviors
unique to dogs, like "bark()" or "fetch()."
• Types of Inheritance:
I. Single Inheritance : A subclass derives from a single super-class.
II. Multiple Inheritance : A subclass derives from more than one super-
classes.
III. Multilevel Inheritance : A subclass derives from a super-class which in turn
is derived from another class and so on.
IV. Hierarchical Inheritance : A class has a number of subclasses each of which
may have subsequent subclasses, continuing for a number of levels, so as
to form a tree structure.
V. Hybrid Inheritance : A combination of multiple and multilevel inheritance
so as to form a lattice structure.
•OBJECT MODEL (Cont.)

•Polymorphism
•Generalization and Specialization
•Links and Association
•Aggregation or Composition
•Benefits of Object Model
Polymorphism:

• Polymorphism is a programming concept that allows objects to take on


multiple forms. It enables a single function or method to have different
behaviors based on the object it's acting upon.

• polymorphism allows a single function or method to have different


behaviors based on the object it's acting upon. It enhances code flexibility
and reusability by enabling objects to take on multiple forms and perform
different actions as needed.
• Example:
• Let's consider a simple example using animals:
• We have a parent class called "Animal" with a method called "makeSound()."
This method prints a generic sound for all animals, like "Animal makes a
sound."
• Now, we create child classes like "Dog" and "Cat" that inherit from the
"Animal" class.
• Each child class overrides the "makeSound()" method with its own
implementation. The "Dog" class might print "Woof!" while the "Cat" class
might print "Meow!"
• When we call the "makeSound()" method on a "Dog" object, it prints
"Woof!", and when we call it on a "Cat" object, it prints "Meow!" This is
polymorphism in action— the same method behaves differently depending
on the object it's called upon.
• Generalization and specialization :

• Generalization:
• Definition: Generalization is a process in which common characteristics of
classes are combined to form a class at a higher level of hierarchy. Subclasses
are merged to create a more generalized superclass.
• For example, if you have classes for different types of vehicles like cars, trucks,
and buses, you can generalize them into a superclass called "Vehicle." This
superclass captures the common properties shared by all vehicles, such as
having wheels and being used for transportation. It represents an "is – a – kind
– of" relationship, where each subclass (car, truck, bus) is a kind of vehicle.
• Specialization:
• Definition: Specialization is the opposite of generalization. It involves using
unique features of groups of objects to create specialized classes from
existing classes. Subclasses become specialized versions of the superclass.

• Explanation: Specialization is like breaking down a broad category into more


specific groups based on their unique characteristics. For instance, if you have
a superclass "Animal," you can specialize it into subclasses like "Dog" and
"Cat" based on their distinct traits and behaviors. Each subclass inherits
common features from the superclass but also adds its unique traits. This
creates a more detailed hierarchy where subclasses are specialized versions of
the superclass.
Link and Association:
• Link:

• Definition: A link represents a connection between objects, allowing them to


collaborate with each other. It can be physical or conceptual.
• Explanation: Think of a link as a bridge that connects two objects, enabling
them to interact and share information. For example, in a social network, a
link could represent a connection between two users who are friends.
Through this link, one user can communicate with or access information
about the other user.
• Association:

• Definition: Association represents a relationship between objects of one


or more classes, connecting them through links.
• Explanation: Think of association as a way to describe how objects
interact with each other. Imagine you have different objects, like
students and teachers in a school. Association helps define the
connections between them. For example, the association between a
student and a teacher represents the relationship where the student
learns from the teacher. Each link in this association signifies a specific
interaction between a student and a teacher, such as attending classes or
receiving guidance
Degree of an Association
• Degree of an association denotes the number of classes involved in a
connection.
• Degree may be unary, binary, or ternary.
I. A unary relationship connects objects of the same class.
II. A binary relationship connects objects of two classes.
III. A ternary relationship connects objects of three or more classes.
Cardinality Ratios of Associations
• Cardinality of a binary association denotes the number of instances
participating in an association.

• There are three types of cardinality ratios, namely:


I. One–to–One : A single object of class A is associated with a single object of
class B.
II. One–to–Many : A single object of class A is associated with many objects of
class B.
III. Many–to–Many : An object of class A may be associated with many objects of
class B and conversely an object of class B may be associated with many
objects of class A.

You might also like