OOSD Unit 1 1
OOSD Unit 1 1
There are mainly three categories : Procedure Oriented, Structure Oriented and Object Oriented
Procedure Oriented:
Structure Oriented:
Structure program consist several modules. Each module has set of related functions.
It focuses on algorithm rather than data.
Program divided into independent procedure & procedures have their own local data.
We can also pass parameters in procedure.
There is one entry and one exit point.
It uses sequence structure, decision structure and loop structure.
There may be user defined data type in structure programming.
Maintenance is complex & costly.
Ex. PASCAL, C etc.
What is OOP?
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper Object-oriented programming provides data
way of hiding data so it is less secure. hiding so it is more secure.
Procedural programming uses the concept of Object-oriented programming uses the concept of
procedure abstraction. data abstraction.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
Class has
A class is a set of variables (to represent its attributes)and functions (to describe its behavior)
that act on its variables.
Object has
Object is an instance of a class that holds data (values) in its variables. Data can be accessed by
its functions.
Real Life Examples of Class and Objects with its attributes and behaviour
Objects are key to understanding object-oriented technology. Look around right now and you'll
find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state
(name, color, and breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also
have state (current gear, current pedal cadence, and current speed) and behavior (changing gear,
changing pedal cadence, applying brakes). Identifying the state and behavior for real-world
objects is a great way to begin thinking in terms of object-oriented programming.
Software objects are conceptually similar to real-world objects: they too consist of state and
related behavior. An object stores its state in fields (variables in some programming languages)
and exposes its behavior through methods (functions in some programming languages). Methods
operate on an object's internal state and serve as the primary mechanism for object-to-object
communication. Hiding internal state and requiring all interaction to be performed through an
object's methods is known as data encapsulation— a fundamental principle of object-oriented
programming.
What Is a Class?
In the real world, you'll often find many individual objects all of the same kind. There may be
thousands of other bicycles in existence, all of the same make and model. Each bicycle was built
from the same set of blueprints and therefore contains the same components. In object-oriented
terms, we say that your bicycle is an instance of the class of objects known as bicycles. A class is
the blueprint from which individual objects are created.
Abstraction
Encapsulation
Inheritance
Polymorphism
Abstraction is the essential element of Object Oriented programming (OOP). It refers to the
representation of essential features without including the background details or explanations or
implementations.
Problem
(Processing)
Model
What Is Encapsulation?
Properties of Encapsulation
1. Data Protection: It provides data integrity and maintains the consistency of the object's
state.
2. Information hiding: Encapsulation hides the internal details of an object, protecting the data
from unauthorized access or modification.
What Is Inheritance?
Create new classes (derived classes) from existing classes (base classes)
The derived class inherits the variables and functions of the base class and adds
additional ones!
Provides the ability to re-use existing code
The mechanism of deriving a new class from an old class is called inheritance or
derivation.
The different types of inheritance are single, hierarchical, multiple and multilevel
inheritance.
The derived class is also called as Child Class and the base class is also called as Parent
class.
Sub Class- It is the class that inherits the properties from another class
Super Class- It is the class whose properties are being inherited.
Object-oriented programming allows classes to inherit commonly used state and behavior from
other classes. In this example, Bicycle now becomes the superclass of Mountain Bike, Road
Bike, and Tandem Bike.
Polymorphism is another important OOP concept; Polymorphism is a Greek term which means
the ability to take more than one form.
• Function Overriding:Function Overriding occurs when a derived class has a definition for
one of the member functions of the base class. That base function is said to be overridden.
Virtual Function:A virtual function is a member function that is declared in the base class
using the keyword virtual and is re-defined (Overridden) in the derived class.
Some Key Points About Virtual Functions:
Virtual functions are Dynamic in nature.
They are defined by inserting the keyword “virtual” inside a base class and are always
declared with a base class and overridden in a child class
A virtual function is called during Runtime
Advantages of OOP:
Reusability: It means reusing the same code again and again rather than building them.
OOP allows developers to create code that can be reused in different parts of an
application. This makes development faster and more efficient because developers do not
have to write new code from scratch each time they need to create a new feature.
Modularity: OOP allows developers to break down complex systems into smaller, more
manageable modules. This makes it easier to develop, test, and maintain code because
changes made to one module do not affect other parts of the system.
Data redundancy: OOP allow similar functionality in multiple classes to a user i.e., user
can write common definition and inherit them.
Code Maintenance: Changes and bug fixes can be made to specific objects or classes
without affecting other parts of the system, reducing errors and improving debugging.
Security: OOPs protects data integrity and privacy by restricting direct access and
allowing controlled access through methods.
Design Benefits: It is to design better code with fewer flaws.
Better Productivity: It leads to more work done, finishing a better program having more
inbuilt features and easy writing ,reading and maintenance.
Easily Upgradable & Scalable: OOP enables easy addition and modification of features
without impacting the entire codebase. OOP makes it easier to scale a program to handle an
increasing amount of work or data.
Disadvantages of OOP:
Generosity:
Generosity is a technique for defining software components that have more than one
interpretation depending on the data types of parameters.
It allows the declaration of data items without specifying their exact data type.
Such unknown data types (generic data type) are resolved at the time of their usage based
on the data type of parameters during a function call.
It is a process that allows a function or a class to work with different-different data types.
That type of function is called Template Function.
Model-
A model is a simplification of reality. A model provides the blueprints of a system. Models may
encompass detailed plans, as well as more general plans. A model may be structural, emphasizing
the organization of the system, or it may be behavioral, emphasizing the dynamics of the system.
We build model so that we can better understand system we are developing.
IMPORTANCE OF MODELING:
Testing a physical entity before building it. Both physical models and computer models
are usually cheaper than building a complete system and enable early correction of flaws.
Communication with customers. Architects and product designers build models to show
their customers. Mock-ups are demonstration products that imitate some or all of the
external behaviour of a system.
Visualization. Storyboards of movies, television shows, and advertisements let writers see
how their ideas flow. They can modify awkward transitions, dangling ends, and
unnecessary segments before detailed writing begins.
Reduction of complexity. Perhaps the main reason for modelling, which incorporates all
the previous reasons, is to deal with systems that are too complex to understand directly.
The human mind can cope with only a limited amount of information at one time. Models
reduce complexity by separating out a small number of important things to deal with at a
time.
Through modeling we achieve four aims:
1. The choice of what models to create has a profound influence on how a problem is
attacked and how a solution is shaped.
If you build a system through the eyes of a database developer, you will likely focus on entity-
relationship models that push behavior into triggers and stored procedures. If you build a system
through the eyes of a structured analyst, you will likely end up with models that are algorithmic-
centric, with data flowing from process to process. If you build a system through the eyes of an
object-oriented developer, you'll end up with a system whose architecture is centered around a
sea of classes and the patterns of interaction that direct how those classes work together.
A quick and simple executable model of the user interface is exactly what you need; at other
times, you have to get down and dirty with the bits, such as when you are specifying cross-
system interfaces or wrestling with networking bottlenecks. In any case, the best kinds of models
are those that let you choose your degree of detail, depending on who is doing the viewing and
why they need to view it. An analyst or an end user will want to focus on issues of what; a
developer will want to focus on issues of how. Both of these stakeholders will want to visualize a
system at different levels of detail at different times.
Achilles heel of structured analysis techniques is the fact that there is a basic disconnect between
its analysis model and the system's design model. Failing to bridge this chasm causes the system
as conceived and the system as built to diverge over time. In object-oriented systems, it is
possible to connect all the nearly independent views of a system into one semantic whole.
The operative phrase here is "nearly independent." In this context, it means having models that
can be built and studied separately but that are still interrelated. As in the case of a building, you
can study electrical plans in isolation, but you can also see their mapping to the floor plan and
perhaps even their interaction with the routing of pipes in the plumbing plan.
There are several ways to approach a model. The two most common ways are from an
algorithmic perspective and from an object-oriented perspective.
1. Object Model
It represents the static structure of the application.
It specifies to whom it happens to.
Operations in an object model correspond to events in dynamic models and functions in
functional models.
It is represented using class diagrams.
2. Dynamic Model
It represents the essential behavior of the application.
It specifies when it happens.
Dynamic model describes the control structure of the objects. It defines decisions which are
dependents of object values and which can cause action to change object values and invoke
their functions.
It is represented using state diagrams.
3. Functional Model
It represents what the application does and not how it does.
It specifies what happens.
It describes functions to be invoked by operations in object model and actions in dynamic
models.
It is represented using data flow diagrams.