POLYMORPHISM
POLYMORPHISM in the context of object-oriented programming, is the ability of one type, A,
to appear as and be used like another type, B. This article is an accessible introduction to the
topic, which restricts attention to the object-oriented paradigm. The purpose of polymorphism is
to implement a style of programming called message-passing in the literature[citation needed], in
which objects of various types define a common interface of operations for users.
In strongly typed languages, polymorphism usually means that type A somehow derives from
type B, or type C implements an interface that represents type B. In weakly typed languages
types are implicitly polymorphic.
Operator overloading of the numeric operators (+, -, *, and /) allows polymorphic treatment of
the various numerical types: integer, unsigned integer, float, decimal, etc; each of which have
different ranges, bit patterns, and representations. Another common example is the use of the "+"
operator which allows similar or polymorphic treatment of numbers (addition), strings
(concatenation), and lists (attachment). This is a lesser used feature of polymorphism.
The primary usage of polymorphism in industry (object-oriented programming theory) is the
ability of objects belonging to different types to respond to method, field, or property calls of the
same name, each one according to an appropriate type-specific behavior. The programmer (and
the program) does not have to know the exact type of the object in advance, and so the exact
behavior is determined at run-time (this is called late binding or dynamic binding).
The different objects involved only need to present a compatible interface to the clients' (calling
routines). That is, there must be public or internal methods, fields, events, and properties with the
same name and the same parameter sets in all the superclasses, subclasses and interfaces. In
principle, the object types may be unrelated, but since they share a common interface, they are
often implemented as subclasses of the same superclass. Though it is not required, it is
understood that the different methods will also produce similar results (for example, returning
values of the same type).
Polymorphism is not the same as method overloading or method overriding.[1] Polymorphism is
only concerned with the application of specific implementations to an interface or a more generic
base class. Method overloading refers to methods that have the same name but different
signatures inside the same class. Method overriding is where a subclass replaces the
implementation of one or more of its parent's methods. Neither method overloading nor method
overriding are by themselves implementations of polymorphism.[2]
Encapsulation:Encapsulation is the process of combining data and functions into a single
unit called class. Using the method of encapsulation, the programmer cannot directly access the
data. Data is only accessible through the functions present inside the class. Data encapsulation
led to the important concept of data hiding. Data hiding is the implementation details of a class
that are hidden from the user. The concept of restricted access led programmers to write
specialized functions or methods for performing the operations on hidden members of the class.
Attention must be paid to ensure that the class is designed properly.
Neither too much access nor too much control must be placed on the operations in order to make the
class user friendly. Hiding the implementation details and providing restrictive access leads to the
concept of abstract data type. Encapsulation leads to the concept of data hiding, but the concept of
encapsulation must not be restricted to information hiding. Encapsulation clearly represents the ability
to bundle related data and functionality within a single, autonomous entity called a class.
Features and Advantages of the concept of Encapsulation:
* Makes Maintenance of Application Easier:
Complex and critical applications are difficult to maintain. The cost associated with maintaining
the application is higher than that of developing the application properly. To resolve this
maintenance difficulty, the object-oriented programming language C++ created the concept of
encapsulation which bundles data and related functions together as a unit called class. Thus,
making maintenance much easier on the class level.
* Improves the Understandability of the Application
* Enhanced Security:
There are numerous reasons for the enhancement of security using the concept of Encapsulation
in C++. The access specifier acts as the key strength behind the concept of security and provides
access to members of class as needed by users. This prevents unauthorized access. If an
application needs to be extended or customized in later stages of development, the task of adding
new functions becomes easier without breaking existing code or applications, there by giving an
additional security to existing application.
Inheritence:Inheritance is the process by which new classes called derived classes are created
from existing classes called base classes. The derived classes have all the features of the base class and
the programmer can choose to add new features specific to the newly created derived class.
Features or Advantages of Inheritance:
Reusability: Inheritance helps the code to be reused in many situations. The base class is defined
and once it is compiled, it need not be reworked. Using the concept ofinheritance , the
programmer can create as many derived classes from the base class as needed while adding
specific features to each derived class as needed.
Saves Time and Effort: The above concept of reusability achieved by inheritance saves the
programmer time and effort. Since the main code written can be reused in various situations as
needed.
Increases Program Structure which results in greater reliability
Inheritance is the concept to inherit the properties of one class to another class. This has also
known as class structure again. For example, classes A contains two-member function ads and
subtracts and class b contain two another functions multiply and divide. We want to use all these
function with one object then we need to use inheritance where class B inherits all the property
of class, which is public, but class B cannot use the private properties of class A. There are
following types of inheritance:
1. Single class Inheritance:
When class a gas inherited in class has known as base class and B class is know as derived class.
Here only two classes have linked to each other.
2. Multilevel Inheritance:
In this type of inheritance, there are number of level and it has used in that cases where we want
to use all properties in number of levels according to the requirement. For example, class A
inherited in class b and class b has inherited in class c for class b so on. Where class A is base
class c. In another way we can say b is derived class a base class for c and a indirect base class
for c is indirect base class for c and c indirect derived class for class A.
3. Multiple Inheritances:
In this type of inheritance, number of classes has inherited in a single class. Where two or more
classes are, know as base class and one is derive class.
4. Hierarchical Inheritance:
This type of inheritance helps us to create a baseless for number of classes and those numbers of
classes can have further their branches of number of class.
5. Hybrid Inheritance:
In this type of inheritance, we can have mixture of number of inheritances but this can generate
an error of using same name function from no of classes, which will bother the compiler to how
to use the functions. Therefore, it will generate errors in the program. This has known as
ambiguity or duplicity.
Abstract Classes:
An abstract class is a class that is designed to be specifically used as a base class. An abstract
class contains at least one pure virtual function. You declare a pure virtual function by using a
pure specifier (= 0) in the declaration of a virtual member function in the class declaration.
The following is an example of an abstract class:
class AB {
public:
virtual void f() = 0;
};
Specialization:An entity set may include subgroupings of entities that are distinct in
some wayfrom other entities in the set. For instance, a subset of entities within an entity set may
have attributes that are not shared by all the entities in the entity set. The E-R model provides a
means for representing these distinctive entity groupings. Consider an entity set person, with
attributes name, street, and city. A personmay be further classified as one of the following:
• customer
• employee
Each of these person types is described by a set of attributes that includes all the attributes of
entity set person plus possibly additional attributes. For example, customer entities may be
described further by the attribute customer-id, whereas employee entities may be described
further by the attributes employee-id and salary. The process of designating subgroupings within
an entity set is called specialization. The specialization of person allows us to distinguish among
persons according to whether they are employees or customers.
Generalization:The design process may also proceed in a bottom-up manner, in which
multiple entity sets are synthesized into a higher-level entity set on the basis of common features.
The database designer may have first identified a customer entity set with the attributes name,
street, city, and customer-id, and an employee entity set with the attributes name, street, city,
employee-id, and salary. There are similarities between the customer entity set and the employee
entity set in the sense that they have several attributes in common. This commonality can be
expressed by generalization, which is a containment relationship that exists between a higherlevel entity set and one or more lower-level entity sets. In our example, person is the higher-level
entity set and customer and employee are lower-level entity sets.
Higher- and lower-level entity sets also may be designated by the terms superclass and subclass,
respectively. The person entity set is the superclass of the customer and employee subclasses.For
all practical purposes, generalization is a simple inversion of specialization. We will apply both
processes, in combination, in the course of designing the E-R schema for an enterprise. In terms
of the E-R diagram itself, we do not distinguish between specialization and generalization. New
levels of entity representation will be distinguished (specialization) or synthesized
(generalization) as the design schema comes to express fully the database application and the
user requirements of the database. Differences in the two approaches may be characterized by
their starting point and overall goal.Generalization proceeds from the recognition that a number
of entity sets share some common features (namely, they are described by the same attributes and
participatein the same relationship sets).
Aggregation:
Aggregation is an abstraction in which relationship sets (along with their associated entity sets)
are treated as higher-level entity sets, and can participate in relationships.
Procedure Oriented Programming (POP)
1. Main program is divided into small parts depending on the functions.
2. The Different part of the program connects with each other by parameter passing & using
operating system.
3. Every function contains different data.
4. Functions get more importance than data in program.
5. Most of the functions use global data.
6. Same data may be transfer from one function to another
7. There is no perfect way for data hiding.
8. Functions communicate with other functions maintaining as usual rules.
9. Example: Pascal, Fortran
[!] Object Oriented Programming (OOP)
1. Main program is divided into small object depending on the problem.
2. Functions of object linked with object using message passing.
3. Data & functions of each individual object act like a single unit.
4. Data gets more importance than functions in program.
5. Each object controls its own data.
6. Data does not possible transfer from one object to another.
7. Data hiding possible in OOP which prevent illegal access of function from outside of it. This
is one of the best advantages of OOP also.
8. One object link with other using the message passing.
9. Example: C++, Java.
UML:
UML (Unified Modelling Language) is a graphic language to depict processes and objects. With
this, one could illustrate the relationship between our general and special wheel. In software
development, UML is utilized to create the logical general view of software.
The Unified Modeling Language (UML) is a standard language for specifying, visualizing,
constructing, and documenting the artifacts of software systems, as well as for business modeling
and other non-software systems. The UML represents a collection of best engineering practices
that have proven successful in the modeling of large and complex systems. The UML is a very
important part of developing object oriented software and the software development process. The
UML uses mostly graphical notations to express the design of software projects. Using the UML
helps project teams communicate, explore potential designs, and validate the architectural design
of the software.
UML Diagrams
Each UML diagram is designed to let developers and customers view a software system from a
different perspective and in varying degrees of abstraction. UML diagrams commonly created in
visual modeling tools include:
Use Case Diagram displays the relationship among actors and use cases.
Class Diagram models class structure and contents using design elements such as classes,
packages and objects. It also displays relationships such as containment, inheritance, associations
and others.
Interaction Diagrams
• Sequence Diagram displays the time sequence of the objects participating in the interaction.
This consists of the vertical dimension and horizontal dimension .
• Collaboration Diagram displays an interaction organized around the objects and their links to
one another. Numbers are used to show the sequence of messages.
State Diagram displays the sequences of states that an object of an interaction goes through
during its life in response to received stimuli, together with its responses and actions.
Activity Diagram displays a special state diagram where most of the states are action states and
most of the transitions are triggered by completion of the actions in the source states. This
diagram focuses on flows driven by internal processing.
Physical Diagrams
• Component Diagram displays the high level packaged structure of the code itself.
Dependencies among components are shown, including source code components, binary code
components, and executable components. Some components exist at compile time, at link time,
at run times well as at more than one time
• Deployment Diagram displays the configuration of run-time processing elements and the
software components, processes, and objects that live on them.
Software component instances represent run-time manifestations of code units.
Lets start of by looking at a class diagram, The first diagram is off PERSON Class.
The data structure called Person has the following attributes.
1. First name
2. Last name
3. Age
4. Weight
with the following methods or operations for The Person object:1. set_first_name
2. get_first_name
3. set_last_name
4. get_middle_name etc..
To draw this in UML Notation, look at the diagram shown below.
A rectangle box is drawn, which is partitioned into three sections.
The top section is were you put the name of the class.
The middle section is for the attributes.
The bottom section you write the operations (which are going to be used to change the state of
the attributes)
Aggregation:
Aggregation differs from ordinary composition in that it does not imply ownership. In composition,
when the owning object is destroyed, so are the contained objects. In aggregation, this is not necessarily
true. For example, a university owns various departments (e.g., chemistry), and each department has a
number of professors. If the university closes, the departments will no longer exist, but the professors in
those departments will continue to exist. Therefore, a University can be seen as a composition of
departments, whereas departments have an aggregation of professors. In addition, a Professor could
work in more than one department, but a department could not be part of more than one university.
Composition is usually implemented such that an object contains another object.
Sometimes aggregation is referred to as composition when the distinction between ordinary
composition and aggregation is unimportant.
Containment:
Composition that is used to store several instances of the composited data type is referred to as
containment. Examples of such containers are arrays, linked lists, binary trees and ociative arrays
In UML, containment is depicted with a multiplicity of 1 or 0..n (depending on the issue of ownership),
indicating that the data type is composed of an unknown amount of instances of the composited data
type.
In UML, composition is depicted as a filled diamond and a solid line. Aggregation is depicted as an open
diamond and a solid line. The below image shows compositions, and then aggregation. The code below
shows what the source code is likely to look like.
© Copyright 2026 Paperzz