Programmer Must Understand — Object-Oriented Paradigm
JIMS Vasant Kunj-II, BCA Department of Information Technology teaches all object Oriented and Object-Based Languages. It provides the best BCA Course in Delhi. Every Year the BCA department ensures to provide the best curriculum and tries to keep updated the students with all concepts in depth. The BCA faculties try to make the base strong of all students and take them to the depth of the subject.
Technology has upgraded itself in always but still, the object-oriented paradigm is used by all languages in demand. To implement the features of various object-oriented Languages, it is required to understand the OOP’s paradigm.
Object-oriented programming is a concept that was created because of the need to overcome the problems that were found with using structured programming techniques. While structured programming uses an approach which is top down, OOP uses an approach which is bottom up. Object oriented programming emphasis on objects and information or classes. With object-oriented programming, a problem will be broken down into a number of units. These units are called objects
The object-oriented (OO) analysis and paradigm is well understood from the initial concept of a programming approaches and the implementation is the logical result of the wide adoption of OO programming languages.
History of Object-Oriented Programming- a new paradigm
History of Object-Oriented Programming Languages
Introduction to OO Paradigm
Object Oriented paradigm is a significant methodology for the development of any software. Most of the architecture styles or patterns such as pipe and filter, data repository, and component-based can be implemented by using this paradigm.
Object means a real word entity that can be defined in terms of its data members and Member Functions. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts:
• Object
• Class
• Data Encapsulation
• Data Abstraction
• Inheritance
• Polymorphism
• Dynamic Binding
• Message Passing
Basic concepts and terminologies of object-oriented systems are defined as−
OBJECT
• Objects are basic building blocks for designing programs.
• An object is a collection of data members and associated member functions.
• An object is an instance of a class.
• Each object is identified by a unique name. Each object must be a member of a particular class.
• An object is the entity that is created to allocate memory.
• A class when defined does not have a memory chunk itself which will be allocated as soon as objects are created.
• For example An object may represent a person, place, or a table of data chair, pen, table, keyboard, bike, etc. It can be a physical and logical entity.
Syntax
Objects can be modeled according to the needs of the application. An object may have a physical existence, like a customer, a car, etc.; or an intangible conceptual existence, like a project, a process, etc.
CLASS
A class is a data type that has its own members i.e., data members and member functions It gives the blueprint or the description of the objects that can be created from it. The creation of an object as a member of a class is called instantiation. Thus, an object is an instance of a class.
Some important properties of the class are −
▰ Class is a user-defined data type.
▰ A class contains members like data members and member functions.
▰ Data members are variables of the class.
▰ Member functions are the methods that are used to manipulate data members.
▰ Data members define the properties of the class whereas the member functions define the behavior of the class.
A class can have multiple objects which have properties and behavior in common for all of them.
Example
Let us consider a simple class, Circle, that represents the geometrical figure circle in a two–dimensional space. The attributes of this class can be identified as follows −
- x–coord, to denote x–coordinate of the center
- y–coord, to denote y–coordinate of the center
- a, to denote the radius of the circle
Some of its operations can be defined as follows −
- findArea (), a method to calculate the area
- findCircumference (), a method to calculate the circumference
- scale (), a method to increase or decrease the radius
ENCAPSULATION
Encapsulation is the process of binding both attributes and methods together within a class. Through encapsulation, the internal details of a class can be hidden from the outside. It permits the elements of the class to be accessed from outside only through the interface provided by the class.
POLYMORPHISM
Polymorphism is originally a Greek word that means the ability to take multiple forms.
▰ Poly — many
▰ Morphos — forms.
In an object-oriented paradigm, polymorphism implies using operations in different ways, depending upon the instances they are operating upon. Polymorphism allows objects with different internal structures to have a common external interface. Polymorphism is particularly effective while implementing inheritance.
The ability of an operator and function to take multiple forms is known as Polymorphism. It allows a single object, method, operator associated with different meanings depending on the type of data passed to it. The different types of polymorphism are
· Operator overloading
· Function overloading.
Let us consider two classes, Circle and Square, each with a method findArea (). Though the name and purpose of the methods in the classes are the same, the internal implementation, i.e., the procedure of calculating an area is different for each class. When an object of class Circle invokes its findArea () method, the operation finds the area of the circle without any conflict with the findArea () method of the Square class.
Relationships
In order to describe a system, both dynamic (behavioral) and static (logical) specifications of a system must be provided. The dynamic specification describes the relationships among objects e.g., message passing. And static specification describes the relationships among classes, e.g., aggregation, association, and inheritance.
MESSAGE PASSING
Any application requires a number of objects interacting in a harmonious manner. Objects in a system may communicate with each other by using message passing. Suppose a system has two objects − obj1 and obj2. The object obj1 sends a message to object obj2 if obj1 wants obj2 to execute one of its methods.
COMPOSITION OR AGGREGATION
Aggregation or composition is a relationship among classes by which a class can be made up of any combination of objects of other classes. It allows objects to be placed directly within the body of other classes. Aggregation is referred to as a “part–of” or “has–a” relationship, with the ability to navigate from the whole to its parts. An aggregate object is an object that is composed of one or more other objects.
ASSOCIATION
Association is a group of links having a common structure and common behavior. Association depicts the relationship between objects of one or more classes. A link can be defined as an instance of an association. The Degree of an association denotes the number of classes involved in a connection. The degree may be unary, binary, or ternary.
- A unary relationship connects objects of the same class.
- A binary relationship connects objects of two classes.
- A ternary relationship connects objects of three or more classes.
INHERITANCE
It is a mechanism that permits new classes to be created out of existing classes by extending and refining its capabilities. The existing classes are called the base classes/parent classes/super-classes, and the new classes are called the derived classes/child classes/subclasses.
The subclass can inherit or derive the attributes and methods of the super-class (es) provided that the super-class allows so. Besides, the subclass may add its own attributes and methods and may modify any of the super-class methods. Inheritance defines a “is — a” relationship.
Example
From a class Mammal, a number of classes can be derived such as Human, Cat, Dog, Cow, etc. Humans, cats, dogs, and cows all have the distinct characteristics of mammals. In addition, each has its own particular characteristics. It can be said that a cow “is — a” mammal.
OO Analysis
In the object-oriented analysis phase of software development, the system requirements are determined, the classes are identified, and the relationships among classes are acknowledged. The aim of OO analysis is to understand the application domain and specific requirements of the system. The result of this phase is requirement specification and initial analysis of logical structure and feasibility of a system.
The three analysis techniques that are used in conjunction with each other for object-oriented analysis are object modeling, dynamic modeling, and functional modeling.
OBJECT MODELING
Object modeling develops the static structure of the software system in terms of objects. It identifies the objects, the classes into which the objects can be grouped, and the relationships between the objects. It also identifies the main attributes and operations that characterize each class.
The process of object modeling can be visualized in the following steps −
DYNAMIC MODELING
After the static behavior of the system is analyzed, its behavior with respect to time and external changes needs to be examined. This is the purpose of dynamic modeling.
Dynamic Modeling can be defined as “a way of describing how an individual object responds to events, either internal events triggered by other objects, or external events triggered by the outside world.”
The process of dynamic modeling can be visualized in the following steps −
FUNCTIONAL MODELING
Functional Modeling is the final component of object-oriented analysis. The functional model shows the processes that are performed within an object and how the data changes, as it moves between methods. It specifies the meaning of the operations of object modeling and the actions of dynamic modeling. The functional model corresponds to the data flow diagram of traditional structured analysis.
The process of functional modeling can be visualized in the following steps −
Object-Oriented Design
After the analysis phase, the conceptual model is developed further into an object-oriented model using object-oriented design (OOD). In OOD, the technology-independent concepts in the analysis model are mapped onto implementing classes, constraints are identified, and interfaces are designed, resulting in a model for the solution domain. The main aim of OO design is to develop the structural architecture of a system.
The stages for object-oriented design can be identified as −
OO Design can be divided into two stages − Conceptual design and Detailed design.
Conceptual design
In this stage, all the classes are identified that are needed for building the system. Further, specific responsibilities are assigned to each class. The class diagram is used to clarify the relationships among classes, and an interaction diagram is used to show the flow of events. It is also known as high-level design.
Detailed design
In this stage, attributes and operations are assigned to each class based on their interaction diagram. State machine diagrams are developed to describe the further details of the design. It is also known as low-level design.
DESIGN PRINCIPLES
Following are the major design principles −
Principle of Decoupling
It is difficult to maintain a system with a set of highly interdependent classes, as modification in one class may result in cascading updates of other classes. In an OO design, the tight coupling can be eliminated by introducing new classes or inheritance.
Ensuring Cohesion
A cohesive class performs a set of closely related functions. A lack of cohesion means — a class performs unrelated functions, although it does not affect the operation of the whole system. It makes the entire structure of software hard to manage, expand, maintain, and change.
Open-closed Principle
According to this principle, a system should be able to extend to meet the new requirements. The existing implementation and the code of the system should not be modified as a result of a system expansion. In addition, the following guidelines have to be followed in the open-closed principle −
- For each concrete class, separate interfaces and implementations have to be maintained.
- In a multithreaded environment, keep the attributes private.
- Minimize the use of global variables and class variables.
Dr. Arpana Chaturvedi
HOD-IT (BCA)
Department of Information Technology