Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Unit-1

OOSD (KCS-54) Subject

Basic Concept of OOP


Introduction
Object oriented programming is the principle of
design and development of programs using modular
approach.
 Object oriented programming approach provides
advantages in creation and development of software for
real life application.
 The basic element of object oriented programming is
the data.
 The programs are built by combining data and functions
that operate on the data.
 Some of the OOP’s languages are C++, Java, C #,
Smalltalk, Perl, and Python.
2
Procedural programming
 The procedural programming focuses on
processing of instructions in order to perform
a desired computation.
 The top-down concepts to decompose main
 functions into lower level components for
modular coding purpose.
 Therefore it emphasizes more on doing things
like algorithms.
 This technique is used in a conventional
programming language such as C and
Pascal.
3
O bje ct orie nte d programming

 Object oriented programming (OOP) is a concept that


combines both the data and the functions that operate
on that data into a single unit called the object.
 An object is a collection of set of data known as member
data and the functions that operate on these data known as
member function.
 OOP follows bottom-up design technique.
 Class is the major concept that plays important role in this
approach. Class is a template that represents a group of
objects which share common properties and relationships.

4
Differences
Procedural Programming Object Oriented Programming
Large programs are divided into Programs are divided into
smaller programs known as objects
functions

Data is not hidden and can be Data is hidden and cannot be


accessed by external functions accessed by external functions
Follow top down approach in the Follows bottom-up approach in
program design the program design
Data may communicate with Objects may communicate with
each other through functions each other through functions.
Emphasize is on procedure rather Emphasize is on data rather than
than data procedure

5
Basic Concepts of OOP’s
The following are the major characteristics of OOP’s:

6
An object can be defined as a data field that has unique attributes and behavior.
An object is an element (or instance) of a class; objects have the behaviors of their class.
An object is a data type that can take in collections of key-value pairs.

Objects
Objects are basic building blocks for designing
programs.
An object is a collection of data members and
For example, suppose Bicycle is a class then MountainBicycle , SportsBicycle , TouringBicycle , etc can be
considered as objects of the class.
associated member functions.
An object may represent a person, place or a table
of data. Pankaj

Each object is identified by


a unique name. Each object must
be a member of a particular class.
Example: Apple, orange, mango
are the objects of class fruit.
Class Name: 3rdyearcs1 7
"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.

Classes
The objects can be made user defined data types
with the help of a class.
A class is a collection of objects that have
identical properties, common behavior and
shared relationship.
Once class is defined, any number of objects of
that class is created.
Classes are user defined data types.
A class can hold both data and functions.
For example: Planets, sun, moon
are member of class solar system.
Class Name: Solar System 8
Data Abstraction,
Encapsulation & Data Hiding
 Data Abstraction
Data Abstraction refers to the process of representing
essential features without including background details
or explanations.
Data Encapsulation:
◦ The wrapping of data and functions into a single unit
(class) is called data encapsulation.
◦ Data encapsulation enables data hiding and information
hiding.
◦ Data hiding is a method used in object oriented
programming to hide information within
computer code.
9
Inheritance
Inheritance is the process by which one object
can acquire and use the properties of another
object.
The existing class is known as base class or super class.
The new class is known as derived class or sub class.
The derived class shares some of the properties of the base
class. Therefore a code from a base class can be
reused by a derived class.
So, Inheritance allows a class (subclass) to acquire the properties
and behavior of another class (super-class). It helps to reuse,
customize and enhance the existing code.

10
Overloading
Overloading allows objects to have different
meaning depending upon context.
There are two types of overloading viz.
o Operator Overloading
o Function Overloading
When an existing operator operates on new data
type is called operator overloading.
Function overloading means two or more
function have same name, but differ in the
number of arguments or data type of arguments.

11
Polymorphism
The ability of an operator and function to take
multiple forms is known as Polymorphism.
The different types of polymorphism are operator
overloading and function overloading.

12
Dynamic binding & Message
Passing Binding refers to the linking of a procedure call to the code to be executed in
response tothe call. Dynamic binding also known as late binding means that
the code associated with agiven procedure call is not known until the time of
call at run time.
Dynamic binding:
◦ Binding is the process of connecting one program to another.
◦ Dynamic binding is the process of linking the procedure call
to a specific sequence of code or function at run time or
during the execution of the program.
Message Passing:
◦ In OOP’s, processing is done by sending message to objects.
◦ A message for an object is request for execution of
procedure.
◦ Message passing involves specifying the name of the object,
the name of the function (message) and the information to be
sent.
13
Advantage of OOP’s
The programs are modularized based on the principles of classes
and objects.
Linking code & object allows related objects to share common
code. This reduces code duplication and code reusability.
Creation and implementation of OOP code is easy and reduces
software development time.
The concept of data abstraction separates object specification and
object implementation.
Data encapsulated along with functions. Therefore external non-
member function cannot access or modify data, thus proving data
security.
Easier to develop complex software, because complexity can be
minimized through inheritance.
OOP can communicate through message passing which makes

14
Disadvantage of OOP’s
 Larger program size: OOP’s typically involves more lines
of code than procedural programs.
 Slower Programs: OOP’s typically slower than procedure
based programs, as they typically require more instructions
to be executed.
 Not suitable for all types of programs.
 To convert a real world problem into an object oriented
model is difficult.
 OOP’s software development, debugging and testing tools
are not standardized.
 Polymorphism and dynamic binding also requires
processing time, due to overload of function calls during
run time.
15
Application of OOP’s
Computer graphics applications.
CAD/CAM software
Object-oriented database.
User-Interface design such as windows
Real-time systems.
Simulation and Modeling
Artificial intelligence and expert systems.
Client-Server Systems.

16
Important Questions
2 Marks Question:\
1. Explain: Classes, Objects, Data Abstraction, Data Encapsulation,
Inheritance, and Polymorphism.
What is Base class and derived class?
5 Marks Question:
1. Distinguish between procedural and object oriented programming.
2. Explain the characteristics of OOP’s.
3. Briefly explain the basic concepts of OOP’s.
4. Explain the advantages of OOP’s.
5. Mention disadvantages of OOP’s.
6. Write the applications of OOP’s.

Note: The four pillars of OOPS are:


Inheritance, Polymorphism, Encapsulation and Abstraction.

17
Please go on next PPT or Slide
Thank you

Type text here


PTO-->

18
Genericity is one of the most powerful means for obtaining flexibility in C++ programming
languages. Genericity has different forms and the choice of it has a considerable impact
on expressiveness, modularity, static checkability and efficiency properties of programs.

Generosity:
It is a quality that's a lot like unselfishness. Someone showing generosity is happy to give time,
money, food, or kindness to people in need.. When you show generosity, you might give away
things or money or put others before yourself. But generosity is about more than cash and stuff.

As a developer working on a single project for days, weeks and possibly even months. It gets
boring and your mind will focus on the project at hand, forgetting other things that developers
might encounter.

By looking at what troubles other developers, you learn to maintain your other skillsets while
working on your current project. For example, I will answer questions about C++ or PHP even
though I rarely use them anymore, simply to keep reminding myself that I know those
languages. It will refresh my memory.

It is also useful for developers to learn how to teach their skills to others, which is practical when
working in teams.

Finally, there are always topics that developers don't know any answer for, so they follow it and
wait for someone else to come up with a solution. And then they consider that solution, try and
see if it would work and maybe see if it can be improved.

But developers aren't just helping others. They're helping themselves too!

Generosity reduces stress, supports one's immune system and enhances one's sense of
purpose. So what is it about generosity that makes it so vital to a happy and healthy life.

Generosity/Template: – It is a process that allows a function or a class to work with different data
types (That type of function is called template function).
Generosity is a technique for defining software components that have more than one interpretation
depending on the data type of parameters. The unknown data types are resolved at the time of
their usage based on the data type of parameters.
Object-oriented modeling (OOM) is an approach to model an
application that is used at the beginning of the software life cycle.

Importance of Modelling: Modeling can help the development team better visualize the plan
of their system and allow them to develop more rapidly by helping them build the right thing. The
more complex your project, the more likely it is that you will fail or that you will build the wrong
thing if you do on modeling at all

Principles of UML Modeling

 The choice of model is important. The choice of what models to create has a profound influence
on how a problem is attacked and how a solution is shaped.

 Every model may be expressed at different levels of precision.


 The best models are connected to reality.

 No single model is sufficient.

Unified Modeling Language (UML) is a general purpose modelling language. The main
aim of UML is to define a standard way to visualize the way a system has been designed. It is quite
similar to blueprints used in other fields of engineering.

UML is not a programming language, it is rather a visual language. We use UML diagrams to portray
the behavior and structure of a system. UML helps software engineers, businessmen and system
architects with modelling, design and analysis. The Object Management Group (OMG) adopted Unified
Modelling Language as a standard in 1997.

Need:

 Complex applications need collaboration and planning from multiple teams and hence require a
clear and concise way to communicate amongst them.

 Businessmen do not understand code. So UML becomes essential to communicate with non
programmers essential requirements, functionalities and processes of the system.

 A lot of time is saved down the line when teams are able to visualize processes, user interactions
and static structure of the system.

UML is linked with object oriented design and analysis. UML makes the use of elements and forms
associations between them to form diagrams. Diagrams in UML can be broadly classified as:

1. Structural Diagrams – Capture static aspects or structure of a system. Structural Diagrams


include: Component Diagrams, Object Diagrams, Class Diagrams and Deployment Diagrams.

2. Behavior Diagrams – Capture dynamic aspects or behavior of the system. Behavior diagrams
include: Use Case Diagrams, State Diagrams, Activity Diagrams and Interaction Diagrams.

The image below shows the hierarchy of diagrams according to UML 2.2
Object Oriented Concepts Used in UML –

1. Class – A class defines the blue print i.e. structure and functions of an object.

2. Objects – Objects help us to decompose large systems and help us to modularize our system.
Modularity helps to divide our system into understandable components so that we can build our
system piece by piece. An object is the fundamental unit (building block) of a system which is
used to depict an entity.

3. Inheritance – Inheritance is a mechanism by which child classes inherit the properties of their
parent classes.

4. Abstraction – Mechanism by which implementation details are hidden from user.

5. Encapsulation – Binding data together and protecting it from the outer world is referred to as
encapsulation.

6. Polymorphism – Mechanism by which functions or entities are able to exist in different forms.

Structural UML Diagrams –

1. Class Diagram – The most widely use UML diagram is the class diagram. It is the building block
of all object oriented software systems. We use class diagrams to depict the static structure of a
system by showing system’s classes,their methods and attributes. Class diagrams also help us
identify relationship between different classes or objects.

2. Composite Structure Diagram – We use composite structure diagrams to represent the internal
structure of a class and its interaction points with other parts of the system. A composite
structure diagram represents relationship between parts and their configuration which
determine how the classifier (class, a component, or a deployment node) behaves. They
represent internal structure of a structured classifier making the use of parts, ports, and
connectors. We can also model collaborations using composite structure diagrams. They are
similar to class diagrams except they represent individual parts in detail as compared to the
entire class.

3. Object Diagram – An Object Diagram can be referred to as a screenshot of the instances in a


system and the relationship that exists between them. Since object diagrams depict behaviour
when objects have been instantiated, we are able to study the behaviour of the system at a
particular instant. An object diagram is similar to a class diagram except it shows the instances
of classes in the system. We depict actual classifiers and their relationships making the use of
class diagrams. On the other hand, an Object Diagram represents specific instances of classes
and relationships between them at a point of time.

4. Component Diagram – Component diagrams are used to represent the how the physical
components in a system have been organized. We use them for modelling implementation
details. Component Diagrams depict the structural relationship between software system
elements and help us in understanding if functional requirements have been covered by
planned development. Component Diagrams become essential to use when we design and build
complex systems. Interfaces are used by components of the system to communicate with each
other.

5. Deployment Diagram – Deployment Diagrams are used to represent system hardware and its
software.It tells us what hardware components exist and what software components run on
them.

6. Package Diagram – We use Package Diagrams to depict how packages and their elements have
been organized. A package diagram simply shows us the dependencies between different
packages and internal composition of packages. Packages help us to organise UML diagrams into
meaningful groups and make the diagram easy to understand. They are primarily used to
organise class and use case diagrams.

Behavior Diagrams –

1. State Machine Diagrams – A state diagram is used to represent the condition of the system or
part of the system at finite instances of time. It’s a behavioral diagram and it represents the
behavior using finite state transitions. State diagrams are also referred to as State
machines and State-chart Diagrams . These terms are often used interchangeably.So simply, a
state diagram is used to model the dynamic behavior of a class in response to time and changing
external stimuli.

2. Activity Diagrams – We use Activity Diagrams to illustrate the flow of control in a system. We
can also use an activity diagram to refer to the steps involved in the execution of a use case. We
model sequential and concurrent activities using activity diagrams. So, we basically depict
workflows visually using an activity diagram.An activity diagram focuses on condition of flow
and the sequence in which it happens. We describe or depict what causes a particular event
using an activity diagram.

3. Use Case Diagrams – Use Case Diagrams are used to depict the functionality of a system or a
part of a system. They are widely used to illustrate the functional requirements of the system
and its interaction with external agents(actors). A use case is basically a diagram representing
different scenarios where the system can be used. A use case diagram gives us a high level view
of what the system or a part of the system does without going into implementation details.

4. Sequence Diagram – A sequence diagram simply depicts interaction between objects in a


sequential order i.e. the order in which these interactions take place.We can also use the terms
event diagrams or event scenarios to refer to a sequence diagram. Sequence diagrams describe
how and in what order the objects in a system function. These diagrams are widely used by
businessmen and software developers to document and understand requirements for new and
existing systems.

5. Communication Diagram – A Communication Diagram(known as Collaboration Diagram in UML


1.x) is used to show sequenced messages exchanged between objects. A communication
diagram focuses primarily on objects and their relationships. We can represent similar
information using Sequence diagrams,however, communication diagrams represent objects and
links in a free form.

6. Timing Diagram – Timing Diagram are a special form of Sequence diagrams which are used to
depict the behavior of objects over a time frame. We use them to show time and duration
constraints which govern changes in states and behavior of objects.

7. Interaction Overview Diagram – An Interaction Overview Diagram models a sequence of actions


and helps us simplify complex interactions into simpler occurrences. It is a mixture of activity
and sequence diagrams.

A Conceptual Model:
A conceptual model of the language underlines the three major elements:

• The Building Blocks

• The Rules

• Some Common Mechanisms


Figure – A Conceptual Model of the UML

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:

1. Structural things

2. Behavioral things

3. Grouping things

4. Annotational things : Annotational things are the explanatory parts of UML models. These
are the comments you may apply to describe, illuminate, and remark about any element in a model.
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.

32. 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.

Common Mechanisms:
The UML is made simpler by the four common mechanisms. They are as follows:

1. Specifications

In UML, behind each graphical notation, there is a textual statement denoting the syntax and semantics.
These are the specifications. The specifications provide a semantic backplane that contains all the parts
of a system and the relationship among the different paths.

2. Adornments
Each element in UML has a unique graphical notation. Besides, there are notations to represent the
important aspects of an element like name, scope, visibility, etc.

3. Common Divisions

Object-oriented systems can be divided in many ways. The two common ways of division are −

 Division of classes and objects − A class is an abstraction of a group of similar objects. An object
is the concrete instance that has actual existence in the system.

 Division of Interface and Implementation − An interface defines the rules for interaction.
Implementation is the concrete realization of the rules defined in the interface.

4. Extensibility Mechanisms

UML is an open-ended language. It is possible to extend the capabilities of UML in a controlled manner
to suit the requirements of a system. The extensibility mechanisms are −

 Stereotypes − It extends the vocabulary of the UML, through which new building blocks can be
created out of existing ones.

 Tagged Values − It extends the properties of UML building blocks.

 Constraints − It extends the semantics of UML building blocks.

UML Stereotype
Stereotype is a profile class which defines how an existing metaclass may be extended as part of
a profile. It enables the use of a platform or domain specific terminology or notation in place of,
or in addition to, the ones used for the extended metaclass.
A stereotype cannot be used by itself, but must always be used with one of the metaclasses
it extends. Stereotype cannot be extended by another stereotype.
A stereotype uses the same notation as a class, with the keyword «stereotype» shown before or
above the name of the stereotype. Stereotype names should not clash with keyword names for
the extended model element.

Servlet Stereotype extends Component.


Stereotype can change the graphical appearance of the extended model element by using
attached icons represented by the Image profile class.

Stereotype Servlet with attached custom icon.


Actor is extended by stereotype Web Client with attached custom icon.
Because stereotype is a class, it may have properties. Properties of a stereotype are referred to
as tag definitions. When a stereotype is applied to a model element, the values of the properties
are referred to as tagged values.

Here Device extended by Server stereotype with tag definitions and custom icon.

UML- Architecture
Software architecture provides a basic design of a complete software system. It defines the elements
included in the system, the functions each element has, and how each element relates to one another.
The software architect will take several factors into consideration:

o What will the system be used for?

o Who will be using the system?

o What quality matters to them?

o Where will the system run?

Advantages: Architecture provides high productivity to the software team. The software development
becomes more effective as it comes up with an explained structure in place to coordinate work,
implement individual features, or ground discussions on potential issues.
A clear architecture will help to achieve quality in the software with a well-designed structure using
principles like separation of concerns; the system becomes easier to maintain, reuse, and adapt. The
software architecture is useful to people such as software developers, the project manager, the client,
and the end-user. Each one will have different perspectives to view the system and will bring different
agendas to a project. Also, it provides a collection of several views. It can be best understood as a
collection of five views:

1. Use case view

2. Design view

3. Implementation view

4. Process view

5. Development view

Use case view

o It is a view that shows the functionality of the system as perceived by external actors.

o It reveals the requirements of the system.

o With UML, it is easy to capture the static aspects of this view in the use case diagrams, whereas
its dynamic aspects are captured in interaction diagrams, state chart diagrams, and activity
diagrams.

Design View
o It is a view that shows how the functionality is designed inside the system in terms of static
structure and dynamic behavior.

o It captures the vocabulary of the problem space and solution space.

o With UML, it represents the static aspects of this view in class and object diagrams, whereas its
dynamic aspects are captured in interaction diagrams, state chart diagrams, and activity
diagrams.

Implementation View

o It is the view that represents the organization of the core components and files.

o It primarily addresses the configuration management of the systems releases.

o With UML, its static aspects are expressed in component diagrams, and the dynamic aspects are
captured in interaction diagrams, state chart diagrams, and activity diagrams.

Process View

o It is the view that demonstrates the concurrency of the system.

o It incorporates the threads and processes that make concurrent system and synchronized
mechanisms.

o It primarily addresses the system's scalability, throughput, and performance.

o Its static and dynamic aspects are expressed the same way as the design view but focus more on
the active classes that represent these threads and processes.

Deployment View

o It is the view that shows the deployment of the system in terms of physical architecture.

o It includes the nodes, which form the system hardware topology where the system will be
executed.

o It primarily addresses the distribution, delivery, and installation of the parts that build the
physical system.

You might also like