Unit-1 Ooad
Unit-1 Ooad
• Classes are user-defined data types that act as the blueprint for individual objects,
attributes and methods.
• Objects are instances of a class created with specifically defined data. Objects can
correspond to real-world objects or an abstract entity. When class is defined
initially, the description is the only object that is defined.
• Methods are functions that are defined inside a class that describe the behaviors of
an object. Each method contained in class definitions starts with a reference to an
instance object. Additionally, the subroutines contained in an object are called
instance methods. Programmers use methods for reusability or keeping
functionality encapsulated inside one object at a time.
• Attributes are defined in the class template and represent the state of an object.
Objects will have data stored in the attributes field. Class attributes belong to the
class itself.
• Faster development,
• Reusability,
• Reduced complexity
• Increased quality
• Each object has SBI (State,Behaviour,Identity)
• OO Relationship
• Generalization (parent-child relationship)
• Association (student enrolls in course)
• Aggregation (whole/part of relationship)
• Composition (strong form of aggregation)
Introduction
What is Object-Oriented Analysis and Design
OOA: we find and describe business objects or concepts in the problem domain
OOD: we define how these software objects collaborate to meet the requirements.
Attributes and methods.
OOP: Implementation: we implement the design objects in, say, Java, C++, C#, etc.
Definition
Object-oriented analysis and design (OOAD) is a popular technical approach for
analyzing, designing an application, system, or business by applying the object oriented
paradigm
and visual modeling throughout the development life cycles for better communication and
product
quality.
Software development
Software development is dynamic and always undergoing major change.
Systems development refers to all activities that go into producing an information systems
solution. Systems development activities consist of systems analysis, modeling, design,
implementation, testing and maintenance.
A software development methodology is a series of processes describe how the work is
to be carried out to achieve the original goal based on the system requirements.
Abstraction: Classes are built on the basis of abstraction, where a set of similar objects are
observed and their common characteristics are listed. Of all these, the characteristics of concern
to the system under observation are picked up and the class definition is made. The attributes
of no concern to the system are left out. This is known as abstraction. The abstraction of an
object varies according to its application. For instance, while defining a pen class for a
stationery shop, the attributes of concern might be the pen color, ink color, pen type etc.,
whereas a pen class for a manufacturing firm would be containing the other dimensions of the
pen like its diameter, its shape and size etc.
Abstraction is specifying the framework and hiding the implementation level information.
Concreteness will be built on top of the abstraction. It gives you a blueprint to follow to while
implementing the details. Abstraction reduces the complexity by hiding low level details.
Data Encapsulation: Encapsulation is the most basic concept of OOP. It is the way of
combining both data and the functions that operate on that data under a single unit. The only
way to access the data is provided by the functions (that are combined along with the data).
These functions are considered as member functions in C. It is not possible to access the data
directly. If you want to reach the data item in an object, you call a member function in the
object. It will read the data item and return the value to you. The data is hidden, so it is
considered as safe and far away from accidental alternation. Data and its functions are said to
be encapsulated into a single entity. Sometimes, encapsulation is also called protection or
information hiding. In fact, encapsulation, protection and information hiding are three
overlapping concepts.
Definition: Encapsulation
Encapsulation is the inclusion within a program object of all the resources need for the object
to function - basically, the method and the data. The object is said to
"publish its interfaces." Other objects adhere to these interfaces to use the object without having
to be concerned with how the object accomplishes it. The idea is
"don't tell me how you do it; just do it." An object can be thought of as a self-contained atom.
The object interface consists of public methods and instantiate data. Protection and information
hiding are techniques used to accomplish encapsulation of an object. Protection is when you
limit the use of class data or methods. Information hiding is when you remove data, methods
or code from a class's public interface in order to refine the scope of an object. So how are these
three concepts implemented in C? You'll remember that C classes have a public, protected and
private interface. Moving methods or data from public to protected or to private, you are hiding
the information from the public or protected interface. If you have a class A with one public
integer data member d, then the C definition would be...
class A
{
public:
integer d;
};
If you moved that data member from the public scope of the private scope, then you would be
hiding the member. Better said, you are hiding the member from the public interface.
class A
{
private:
integer d;
};
It is important to note that information hiding are not the same as encapsulation. Just because
you protect or hide methods or data, does not mean you are encapsulating an object. But the
ability to protect or hide methods or data, provide the ability to encapsulate an object. You
might say that encapsulating is the proper use of protection and information hiding.
Encapsulation-Encapsulation is a process of binding or wrapping the data and the codes that
operates on the data into a single entity. This keeps the data safe from outside interface and
misuse. One way to think about encapsulation is as a protective wrapper that prevents code and
data from being arbitrarily accessed by other code defined outside the wrapper.In other words,
encapsulation is the ability of an object to be a container (or capsule) for related properties (ie.
data variables) and methods (ie. functions).
Abstraction-The process of abstraction in Java is used to hide certain details and only show
the essential features of the object. In other words, it deals with the outside view of an object
(interface).
Inheritance: Inheritance is another important concept in this regard. This concept is used to
apply the idea of reusability of the objects. A new type of class can be defined using a similar
existing class with a few new features. For instance, a class vehicle can be defined with the
basic functionality of any vehicle and a new class called car can be derived out of it with a few
modifications. This would save the developers time and effort as the classes already existing
are reused without much change.
Inheritance
Several classes may have the same attributes and/or methods. When this occurs, a general class
is created containing the common attributes and methods. The specialized class inherits or
receives the attributes and methods of the general class. In addition, the specialized class has
attributes and methods that are unique and only defined in the specialized class. Creating
generalized classes and allowing the specialized class to inherit the attributes and methods
helps to foster reuse, because the code is used many times. It also helps to maintain existing
program code. This allows the analyst to define attributes and methods once but use them many
times, in each inherited class.
Polymorphism
Polymorphism (meaning many forms), or method overriding (not the same as method
overloading), is the capability of an object-oriented program to have several versions of the
same method with the same name within a superclass/subclass relationship. The subclass
inherits a parent method but may add to it or modify it. The subclass may change the type of
data, or change how the method works. For example, there might be a customer who receives
an additional volume discount, and the method for calculating an order total is modified. The
subclass method is said to override the superclass method.
When attributes or methods are defined more than once, the most specific one (the lowest in
the class hierarchy) is used. The compiled program walks up the chain of classes, looking for
methods.
Polymorphism means existing in many forms. Variables, functions, and objects can exist in
multiple forms in Java and Python. There are two types of polymorphism which are run time
polymorphism and compile-time polymorphism. Run time can take a different form while the
application is running and compile-time can take a different form during compilation.
An excellent example of Polymorphism in Object-oriented programing is a cursor behavior. A
cursor may take different forms like an arrow, a line, cross, or other shapes depending on the
behavior of the user or the program mode. With polymorphism, a method or subclass can define
its behaviors and attributes while retaining some of the functionality of its parent class. This
means you can have a class that displays date and time, and then you can create a method to
inherit the class but should display a welcome message alongside the date and time. The goals
of Polymorphism in Object-oriented programming is to enforce simplicity, making codes more
extendable and easily maintaining applications.
Association
Association is defined as a structural relationship, that conceptually means that the two
components are linked to each other. This kind of relation is also referred to as a using
relationship, where one class instance uses the other class instance or vice-versa, or both may
be using each other. But the main point is, the lifetime of the instances of the two classes are
independent of each other and there is no ownership between two classes.
Association is a relationship between two objects. In other words, association defines the
multiplicity between objects. You may be aware of one-to-one, one-to-many, many-to-one,
many-to-many all these words define an association between objects. Aggregation is a special
form of association. Composition is a special form of aggregation.
Association is a relation between two separate classes which establishes through their
Objects. Association can be one-to-one, one-to-many, many-to-one, many-to-many. In
Object-Oriented programming, an Object communicates to another object to use
functionality and services provided by that object. Composition and Aggregation are the
two forms of association.
Aggregation: Aggregation is the same as association but with an additional point that there is
an ownership of the instances, unlike association where there was no ownership of the
instances. To understand it better, let's add another class named Department to our example
explained above.
Composition is more restrictive. When there is a composition between two objects, the
composed object cannot exist without the other object. This restriction is not there in
aggregation. Though one object can contain the other object, there is no condition that the
composed object must exist. The existence of the composed object is entirely optional. In both
aggregation and composition, direction is must. The direction specifies, which object contains
the other object.
Example: A Library contains students and books. Relationship between library and student is
aggregation. Relationship between library and book is composition. A student can exist without
a library and therefore it is aggregation. A book cannot exist without a library and therefore its
a composition. For easy understanding I am picking this example. Don’t go deeper into
example and justify relationships!
Generalization is the process of extracting shared characteristics from two or more classes,
and combining them into a generalized superclass. Shared characteristics can be attributes,
associations, or methods.
Generalization is the process of taking out common properties and functionalities from
two or more classes and combining them together into another class which acts as the parent
class of those classes or what we may say the generalized class of those specialized classes.
All the subclasses are a type of superclass. So we can say that subclass “is-A” superclass.
Therefore Generalization is termed as “is-A relationship”.
A generalization describes a relationship between a general kind of thing and a more specific
kind of thing. This type of relationship is often described as an “is a” relationship. For example,
a car is a vehicle and a truck is a vehicle. In this case, vehicle is the general thing, whereas car
and truck are the more specific things. Generalization relationships are used for modeling class
inheritance and specialization. A general class is sometimes called a superclass, base class, or
parent class; a specialized class is called a subclass, derived class, or child class.