Oopm (Cs305) Unit-1 Notes
Oopm (Cs305) Unit-1 Notes
Syllabus: Introduction to Object Oriented Thinking & Object-Oriented Programming: Comparison with
Procedural Programming, features of Object-oriented paradigm– Merits and demerits of OO
methodology; Object model; Elements of OOPS, IO processing.
Object oriented methodology provides a new way of viewing the real-world situations. Object-Oriented
refers to a programming language, system or software methodology that is built on the concepts of logical
objects. It works through the creation, utilization and manipulation of reusable objects to perform a specific
task. The object-oriented technique is different from conventional programming, which focuses on
functions/behaviors, while object-oriented works on the interactions of one or more objects.
1
OOP&M CS 305 UNIT I
A car is an example of a complex object, with many attributes. We don’t need to understand all of its internal
mechanics, what kind of engine it has, how the gas makes it run, or even where the gas came from in order
to know how to interact with it. The car’s behaviors have been made simple for us through object-oriented
logic: put the key in the ignition, and the car turns on and gets us where we need to go. The attributes that
make this possible—all of the car’s parts, electronics, and engineering—are a “package” we don’t need to
break down in order to understand.
Object-Oriented Programming
Object-Oriented programming, or OOP, is an approach to problem solving where all computations are
carried out using objects. Code in object-oriented programming is organized around objects. Once you have
your objects, they can interact with each other to make something happen.
Let's say you want to have a program where a person gets into a car and drives it from A to B. You would start
by describing the objects, such as a person and car. That includes methods: a person knows how to drive a
car, and a car knows what it is like to be driven. Once you have your objects, you bring them together so the
person can get into the car and drive.
In OOP, concepts of objects and classes came into existence. The whole program is written in a class
containing different objects and a number of member functions. The main reason behind the OOP is that
the developers can use real-world entities in a program.
In modern software development, object-oriented programming is commonly used for writing huge &
complex software. Object-oriented programming was developed as a method for reducing complexity in
software development, making it easier to build and scale large software programs.
2
OOP&M CS 305 UNIT I
Object
Overloading Class
OOP
Inheritance Abstraction
Encapsulation Polymorphism
Encapsulation
Data Methods
3
OOP&M CS 305 UNIT I
4) Polymorphism
The ability to use an operator or function in different ways in other words giving different meaning or
functions to the operators or functions is called polymorphism. Poly refers to many. That is a single function
or an operator functioning in many ways different upon the usage is called polymorphism.
VEHICLE
FORMS
2-WHEELER 4-WHEELER
3-WHEELER
4
OOP&M CS 305 UNIT I
Comparison between Procedure Oriented Programming (POP) & Object-Oriented Programming (OOP)
5
OOP&M CS 305 UNIT I
6
OOP&M CS 305 UNIT I
Object Model
An object model is a logical interface, software or system that is modeled through the use of Object-Oriented
techniques. It enables the creation of an architectural software or system model prior to development or
programming. An object model is part of the object-oriented programming (OOP) lifecycle.
An object model helps describe or define a software/system in terms of objects and classes. It defines the
interfaces or interactions between different models, inheritance, encapsulation and other object-oriented
interfaces and features.
7
OOP&M CS 305 UNIT I
interface that allows programs and scripts to dynamically access and update the content, structure, and style
of a document.
DOM
INTERFACE
2. Component Object Model (COM): Component Object Model (COM) is a simple Microsoft specification
method that defines a binary standard for exchanging code between two systems, regardless of the
operating system or programming language. COM provides access to distributed client object services and
is used to share cross-platform binary code and programming languages.
COM interactivity occurs via interfacing with expandable COM software components that do not have an
impact on underlying implementation objects. COM uses one intra- and inter-process communication model
for developer transparency. Developers increase efficiency by modifying service implementation. COM
machine components also share memory, which increases efficiency and provides superior error handling
and debugging.
CLIENT SERVER
COM/DOM CORE
Above Figure 1.11 shows the architecture of Microsoft component object model. Here client refers to a piece
of code that is using the services of a COM component. A COM server is any object that provides services to
client. The Interface Definition Language (IDL) describe the interfaces being implemented by objects.
Elements of OOPS
The conceptual framework of Object–Oriented systems is based upon the object model. There are two
categories of elements in an Object-Oriented system: -
8
OOP&M CS 305 UNIT I
Minor Elements− By minor, it is meant that these elements are useful, but not indispensable part of the
object model. The three minor elements are −
Typing
Concurrency
Persistence
1) Modularity
Modularity is the process of decomposing a problem (program) into a set of modules so as to reduce the
overall complexity of the problem. Booch has defined modularity as- “Modularity is the property of a system
that has been decomposed into a set of cohesive and loosely coupled modules”.
Modularity is intrinsically linked with encapsulation. Modularity can be visualized as a way of mapping
encapsulated abstractions into real, physical modules having high cohesion within the modules and their
inter– modules interaction or coupling is low.
2) Hierarchy
In Grady Booch’s words, “Hierarchy is the ranking or ordering of abstraction”. Through hierarchy, a system
can be made up of interrelated subsystems, which can have their own subsystems and so on until the
smallest level components are reached. It uses the principle of “divide and conquer”. Hierarchy allows code
reusability.
The two types of hierarchies in OOA are −
“IS–A” hierarchy − It defines the hierarchical relationship in inheritance, whereby from a super-class, a
number of subclasses may be derived which may again have subclasses and so on. For example, if we derive
a class car from a class vehicle, we can say that a car “is–a” vehicle.
“PART–OF” hierarchy − It defines the hierarchical relationship in aggregation by which a class may be
composed of other classes. For example, a CPU is composed of hard disk, motherboard and power supply. It
can be said that motherboard is a “part-of” CPU.
9
OOP&M CS 305 UNIT I
3) Typing
In OOP, a class is visualized as a type having properties distinct from any other types. Typing is the
enforcement of the notion that an object is an instance of a single class.
The two types of typing are: -
Strong Typing − Here, the operation on an object is checked at the time of compilation.
Weak Typing − Here, messages may be sent to any class. The operation is checked only at the time of
execution.
4) Concurrency
Concurrency in operating systems allows performing multiple tasks or processes simultaneously. When a
single process exists in a system, it is said that there is a single thread of control. However, most systems
have multiple threads, some active, some waiting for CPU, some suspended, and some terminated. Systems
with multiple CPUs inherently permit concurrent threads of control; but systems running on a single CPU use
appropriate algorithms to give equitable CPU time to the threads so as to enable concurrency.
In an Object-Oriented environment, there are active and inactive objects. The active objects have
independent threads of control that can execute concurrently with threads of other objects. The active
objects synchronize with one another as well as with purely sequential objects.
5) Persistence
An object occupies a memory space and exists for a particular period of time. In traditional programming,
the lifespan of an object was typically the lifespan of the execution of the program that created it. In files or
databases, the object lifespan is longer than the duration of the process creating the object. This property
by which an object continues to exist even after its creator ceases to exist is known as persistence.
IO processing
Every program takes some data as input and generates processed data as output following the cycle input-
process-output. C++ uses the concept of streams and stream classes to implement its I/O operations with
the console and disk files. Input and output functionality is not defined as part of the core C++ language, but
rather is provided through the C++ standard library (and thus resides in the std namespace).
Streams
A stream is just a sequence of bytes that can be accessed sequentially. Over time, a stream may produce or
consume potentially unlimited amounts of data. The stream library's unified approach makes it very friendly
to use. Using a consistent interface for outputting to the screen and sending files over a network makes life
easier. The programs below will show you what is possible.
Streams work with built-in data types, and you can make user-defined types work with streams
by overloading the insertion operator (<<) to put objects into streams, and the extraction operator (>>) to
read objects from streams.
10
OOP&M CS 305 UNIT I
Typically, we deal with two different types of streams. Input streams are used to hold input from a data
producer, such as a keyboard, a file, or a network. For example, the user may press a key on the keyboard
while the program is currently not expecting any input. Rather than ignore the users key press, the data is
put into an input stream, where it will wait until the program is ready for it.
Output streams are used to hold output for a particular data consumer, such as a monitor, a file, or a printer.
When writing data to an output device, the device may not be ready to accept that data yet - for example,
the printer may still be warming up when the program writes data to its output stream.
Stream classes
The I/O system contains a hierarchy of classes that are used to define various streams to deal with both the
console and disk files. These classes are called stream classes. Figure 1.14 shows hierarchy of stream classes
used for input and output operations with the console unit. These classes are declared in the header file
iostream. This file should be included in all the programs that communicate with console unit.
ios is the base class for istream (input stream) and ostream (output stream) which are base classes for
iostream, (input/output stream). The class ios provides the basic support for formatted and unformatted I/O
operations.
11