Unit1 Oosd
Unit1 Oosd
INTRODUCTION:
1.1 Object Orientation-
End users of computer systems as well as computer- based systems can notice the effects of object-oriented
design (OOD) in the form of increasingly easy-to-use-
➢ Software Applications
➢ Database Management Systems
➢ Operating System
In object-oriented programming (OOP), more emphasis is given to the data rather than functions. In OOP,
data is encapsulated with the associated functions that operate on it. Thatgives rise to a concept called data
encapsulation. In OOP, the real-life problem can be decomposed into a number of entities called Objects and
then data and functions are built around these objects. The organization of data and functions in an object-
oriented programming is shown in fig.
Adding new data and function is not Adding new data and function is
easy. easy.
Procedural programming does not Object oriented programming
have any proper way for hiding data provides data hiding so it is more
so it is less secure. secure.
Merits:
• Easier Troubleshooting
• Code Reusability
• Data Redundancy
• Code Flexibility
• Polymorphism Flexibility
• Better Productivity
• Security
Demerits:
• It requires more data protection.
• Inadequate for concurrent problems
• Inability to work with existing systems.
• Compile time and run time overhead.
• Unfamiliarity causes training overheads.
What do you understand by object identity
Object identity is a property of data that is created in the context of an object data model, where an object
is assigned a unique internal object identifier, or oid. The object identifier is used to define associations
between objects and to support retrieval and comparison of object-oriented data based on the internal
identifier rather than the attribute values of an object.
• In an object data model, an object is created as an instance of a class. An object has an object identifier
as well as a state.
• An object identifier is immutable, meaning that the value of the object identifier cannot change over the
lifetime of the object.
• The state, on the other hand, is mutable, representing the attributes that describe the object and the
relationships that define associations among objects.
• Relationships in an object data model are defined using object references based on internal object
identifiers rather than attribute...
Class: A class in C++ is the building block that leads to Object-Oriented programming. It isa user-defined
data type, which holds its own data members and member functions, which can be accessed and used by
creating an instance of that class.
For Example: Consider the Class of Cars. There may be many cars with different names and brand
but all of them will share some common properties like all of them will have 4 wheels, Speed Limit,
Mileage range etc. So here, Car is the class and wheels, speed limits, mileage are their properties.
• A Class is a user defined data-type which has data members and member functions.
• Data members are the data variables and member functions are the functions used to manipulate these
variables and together these data members and member functions defines the properties and behavior
of the objects in a Class.
• In the above example of class Car, the data member will be speed limit, mileage etc and member
functions can be applying brakes, increase speed etc.
An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e., an object is created) memory is allocated.
ENCAPSULATION:
Encapsulation is one of the key features of object-oriented programming. It involves the bundling of data
members and functions inside a single class. Bundling similar data members and functions inside a class
together also helps in data hiding.
C++ Encapsulation: In general, encapsulation is a process of wrapping similar code in one place. In C++, we
can bundle data members and functions that operate together inside a single class. For example,
class Rectangle {
public:
int length;
int breadth;
int getArea() {
return length * breadth;
}
};
In the above program, the function getArea() calculates the area of a rectangle. To calculate the area, it needs
length and breadth.
Hence, the data members (length and breadth) and the function getArea() are kept together in
the Rectangle class.
Why Encapsulation?
• In C++, encapsulation helps us keep related data and functions together, which makes our code cleaner
and easy to read.
• It helps to control the modification of our data members.
Consider a situation where we want the length field in a class to be non-negative. Here we can make
the length variable private and apply the logic inside the method setAge(). For example,
class Rectangle {
private:
int age;
public:
void setLength(int len) {
if (len >= 0)
length = len;
}
};
• The getter and setter functions provide read-only or write-only access to our class members. For
example,
getLength() // provides read-only access
setLength() // provides write-only access
• It helps to decouple components of a system. For example, we can encapsulate code into multiple
bundles.
These decoupled components (bundles) can be developed, tested, and debugged independently and
concurrently. And any changes in a particular component do not have any effect on other components.
In normal terms Encapsulation is defined as wrapping up of data and information under a single unit. In
Object Oriented Programming, Encapsulation is defined as binding together the data and the functions that
manipulates them.
Consider a real-life example of encapsulation; in a company there are different sections like the accounts
section, finance section, sales section etc. The finance section handles all the financial transactions and keep
records of all the data related to finance. Similarly, the sales section handles all the sales related activities
and keeps records of all the sales.
Now there may arise a situation when for some reason an official from finance section needs all the data
about sales in a particular month. In this case, he is not allowed to directly access the data of sales section.
He will first have to contact some other officer in the sales section and then request him to give the
particular data. This is what encapsulation is. Here the data of sales section and the employees that can
manipulate them are wrapped under a single name “sales section”.
Information/Data Hiding:
• Data hiding is a way of restricting the access of our data members by hiding the implementation details.
Encapsulation also provides a way for data hiding.
• Is the process whereby the details that show how the programmed program came into function are hidden
to avoid access of these details of function to the public users, so it is private and protected act.
• We can use access modifiers to achieve data hiding in C++.
• It supports information hiding by allowing private: and protected: sections in class declarations.
• A "supported" way to violate it is via the friend keyword, that allows external functions or classes to
access the private and protected members of a class (although it's debatable if that's actually a
"violation").
Also, in a C++ program there's no runtime enforcing of the visibility rules, so if you manage to get a
pointer to an internal field or a function pointer to an internal method nothing stops you from using it
(again, this may be intentional - the class itself gave you that pointer - or "abusive" - you have a pointer
to the object itself and add some offset to get to an internal member).
POLYMORPHISM:
Polymorphism is the ability of any data to be processed in more than one form. Polymorphism is one
of the most important concepts of object-oriented programming language. The most common use
of polymorphism in object- oriented programming occurs when a parent class reference is used to refer to a
child class object.
For example, you have a Smartphone for communication. The communication mode you choose could be
anything. It can be a call, a text message, a picture message, mail, etc. So, the goal is common that is
communication, but their approach is different. This is called Polymorphism.
Real life example of polymorphism, a person at the same time can have different roles toplay in life. Like
a woman at the same time is a mother, a wife, an employee and a daughter. So, the same person has to have
many features but has to implement each as per the situation and the condition. Polymorphism is considered
as one of the important features of Object-Oriented Programming.
• Runtime Polymorphism
c. Visualization:
i. Storyboards of movies, television shows, and advertisements allow the writers to see how their idea flows.
ii. Using models unnecessary segments can be modified before the final development begins.
d. Reduction of complexity:
i. Modeling helps in understanding the systems that are too complex to understand directly.
ii. Model reduces complexity by leaving out the non-essential details
Object oriented modelling:
a. Analysis
• The main goal of the analysis is to build models of the world.
• The requirements of the users, developers and managers provide the information needed to develop the
initial problem statement.
b. OMT Models
I. Object Model
II. Dynamic Model
III. Functional Model
c. Design
• It specifies all of the details needed to describe how the system will be implemented. Manipulators are helping
functions. It is used to manipulate or modify the input or output stream. The modification is possible by using the
insertion (<<) and extraction (>>) operators.
• Object-oriented modelling (OOM) is the construction of objects using a collection of objects that
contain stored values of the instance variables found within an object. Unlike models that are
record-oriented, object-oriented values are solely objects.
• The object-oriented modelling approach creates the union of the application and database development
and transforms it into a unified data model and language environment. Object-oriented modeling
allows for object identification and communication while supporting data abstraction, inheritance
and encapsulation.
• Object-oriented modeling is the process of preparing and designing what the model’s code will
actually, look like. During the construction or programming phase, the modeling techniques
are implemented by using a language that supports the object-oriented programming model.
Need of Object-Oriented Data Model:
To represent the complex real-world problems there was a need for a data model that is closely related to
real world. Object Oriented Data Model represents the real-world problems easily.
Advantages of Object-Oriented Data Model:
• Codes can be reused due to inheritance.
• Easily understandable.
• Cost of maintenance can reduce due to reusability of attributes and functions because of
inheritance.
Disadvantages of Object-Oriented Data Model:
• It is not properly developed so not accepted by users easily.
Note – Language, Model, and Unified are the important aspect of UML as described in the map above.
1. Language:
• It enables us to communicate about a subject which includes the requirements and the system.
• It is difficult to communicate and collaborate for a team to successfully develop a system without a
language.
2. Model:
• It is a representation of a subject.
• It captures a set of ideas (known as abstractions) about its subject.
3. Unified:
• It is to bring together the information systems and technology industry’s best engineering practices.
• These practices involve applying techniques that allow us to successfully develop systems.
A Conceptual Model:
A conceptual model of the language underlines the three major elements:
Building Blocks:
The vocabulary of the UML encompasses three kinds of building blocks:
1. Things:
Things are the abstractions that are first-class citizens in a model; relationships tie these things
together; diagrams group interesting collections of things.
There are 4 kinds of things in the UML:
1Structural things
2. Behavioral things
3. Grouping things
4. A notational things
These things are the basic object-oriented building blocks of the UML. You use them to write well-
formed models.
2. Relationships:
There are 4 kinds of relationships in the UML:
1. Dependency
2. Association
3. Generalization
4. Realization
These relationships are the basic relational building blocks of the UML.
3. Diagrams:
It is the graphical presentation of a set of elements. It is rendered as a connected graph of vertices
(things) and arcs (relationships).
1. Class diagram
2. Object diagram
3. Use case diagram
4. Sequence diagram
5. Collaboration diagram
6. State chart diagram
7. Activity diagram
8. Component diagram
9. Deployment diagram
Rules:
The UML has a number of rules that specify what a well-formed model should look like. A well-formed
model is one that is semantically self-consistent and in harmony with all its related models.
The UML has semantic rules for:
1. Names – What you can call things, relationships, and diagrams.
2. Scope – The context that gives specific meaning to a name.
3. Visibility – How those names can be seen and used by others.
4. Integrity – How things properly and consistently relate to one another.
5. Execution – What it means to run or simulate a dynamic model.
First, a dependency is a semantic relationship between two model elements in which a change to
one element (the independent one) may affect the semantics of the other element (the dependent
one). Graphically, a dependency is rendered as a dashed line, possibly directed, and occasionally
including a label
Second, an association is a structural relationship among classes that describes a set of links, a link being
a connection among objects that are instances of the classes. Aggregation is a special kind of
association, representing a structural relationship between a whole and its parts. Graphically, an association
is rendered as a solid line, possibly directed, occasionally including a label, and often containing
other adornments, such as multiplicity and end names.
• Composition: Foo has a Bar object as data member -> Foo contains a Bar. It can't exist without it.
• Aggregation: Foo has a pointer to Bar object and manages the lifetime of that object -> Foo
contains a Bar, but can also exist without it.