Docsity

Object-Oriented Programming: Principles, Objects, Classes, and More, Assignments of C programming

Toggle sidebar
bg1
OOP Principles or Basic Concepts of OOP
The prime purpose of C++ programming was to add object orientation to the C programming
language, which is in itself one of the most powerful programming languages.
The core of the pure object-oriented programming is to create an object, in code, that has
certain properties and methods. While designing C++ modules, we try to see whole world in
the form of objects. For example a car is an object which has certain properties such as color,
number of doors, and the like. It also has certain methods such as accelerate, brake, and so on.
There are a few principle concepts that form the foundation of object-oriented programming โˆ’
Objects
Classes
Data abstraction
Data encapsulation
Inheritance
Overloading
Polymorphism
Dynamic binding
Message passing
Objects: Objects are basic building blocks for designing programs. An object may represent a
person, place or a table of data. An object is a collection of data members and associated
member functions. Each object is identified by a unique name. Every object must be a member
of a particular class. Ex: Apple, orange, mango are the objects of class fruit. Objects take up
space in memory and have address associated with them. For example, structure variable in a C
program. At the time of execution of a program, the objects interact by sending messages to
one another. The objects can interact with one another without having to know the details of
data or functions within an object.
Classes: The objects can contain data and code to manipulate the data. The objects can be
made user defined data types with the help of a class. Therefore, objects are variables of the
type class. A class is a way of grouping objects having similar characteristics. Once a class is
defined, any number of objects of that class are created. For example, planets, sun, moon are
pf3
pf4
pf5

Partial preview of the text

Download Object-Oriented Programming: Principles, Objects, Classes, and More and more Assignments C programming in PDF only on Docsity!

OOP Principles or Basic Concepts of OOP The prime purpose of C++ programming was to add object orientation to the C programming language, which is in itself one of the most powerful programming languages. The core of the pure object-oriented programming is to create an object, in code, that has certain properties and methods. While designing C++ modules, we try to see whole world in the form of objects. For example a car is an object which has certain properties such as color, number of doors, and the like. It also has certain methods such as accelerate, brake, and so on. There are a few principle concepts that form the foundation of object-oriented programming โˆ’ Objects Classes Data abstraction Data encapsulation Inheritance Overloading Polymorphism Dynamic binding Message passing Objects: Objects are basic building blocks for designing programs. An object may represent a person, place or a table of data. An object is a collection of data members and associated member functions. Each object is identified by a unique name. Every object must be a member of a particular class. Ex: Apple, orange, mango are the objects of class fruit. Objects take up space in memory and have address associated with them. For example, structure variable in a C program. At the time of execution of a program, the objects interact by sending messages to one another. The objects can interact with one another without having to know the details of data or functions within an object. Classes: The objects can contain data and code to manipulate the data. The objects can be made user defined data types with the help of a class. Therefore, objects are variables of the type class. A class is a way of grouping objects having similar characteristics. Once a class is defined, any number of objects of that class are created. For example, planets, sun, moon are

members of class solar system. Classes are user defined data types. A class can hold both data and functions. Data abstraction: Data abstraction permits the user to use an object without knowing its internal working. Abstraction refers to the process of representing essential features without including background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and functions to operate on these attributes. Data encapsulation : Data encapsulation combines data and functions into a single unit called class. Data encapsulation will prevent direct access to data. The data can be accessed only through methods (function) present inside the class. The data cannot be modified by an external non-member function of a class. Data encapsulation enables data hiding or information hiding. Inheritance : In OOP, the concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. Thus the process of forming a new class from an existing class is known as Inheritance. The objects of one class acquire the properties of another class through inheritance. The existing class is known as base class. The new class is known as derived 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. In addition to this the new class may combine features from two different base classes too. In single inheritance, each subclass has only one superclass. In Multiple inheritance, each subclass has more than one super class.

Message Passing: In OOP, processing is done by sending messages to objects. A message for an object is request for execution of procedure. The request will involve a procedure (function) in the receiving object that generates desired results. Message passing involves specifying the name of object, the name of the function (message) and the information to be sent. Advantages of OOP :

  1. The programs are modularized based on the principle of classes and objects.
  2. Linking code & object allows related objects to share common code. This reduces code duplication and code reusability.
  3. Data is encapsulated along with functions. Therefore, external non- member function cannot access or modify data, thus providing data security.
  4. Easier to develop complex software, because complexity can be minimized through inheritance.
  5. The concept of data abstraction separates object specification and object implementation.
  6. Creation and implementation of OOP code is easy and reduces software development time.
  7. OOP can communicate through message passing which makes interface description with outside system very simple.
  8. We can build the programs from standard working modules that communicate with one another, rather than having to start writing the code from scratch which leads to saving of development time and higher productivity,
  9. OOP language allows to break the program into the bit-sized problems that can be solved easily (one object at a time).
  10. The new technology promises greater programmer productivity, better quality of software and lesser maintenance cost.
  11. OOP systems can be easily upgraded from small to large systems.
  12. It is possible that multiple instances of objects co-exist without any interference,
  13. It is very easy to partition the work in a project based on objects.
  14. It is possible to map the objects in problem domain to those in the program.
  15. The principle of data hiding helps the programmer to build secure programs which cannot be invaded by the code in other parts of the program.
  16. By using inheritance, we can eliminate redundant code and extend the use of existing classes.
  1. Message passing techniques is used for communication between objects which makes the interface descriptions with external systems much simpler.
  2. The data-centered design approach enables us to capture more details of model in an implementable form.