Object modeling uses the object-oriented concepts of encapsulation and polymorphism to model the objects of a system. Ever since programming adapted an object-oriented approach to software development, the need to represent a system’s object grew based on the complexity of the system and requirements.
The object-oriented concepts of encapsulation and polymorphism relate to object models by defining how objects of a program interact, behave, and protect their data from the rest of the program.
Let’s try to understand encapsulation and polymorphism to see how they are related to object modeling.
In English, encapsulation is “the action of enclosing something in or as if in a capsule.” In programming, encapsulation refers to the act of hiding information from certain parts of the program. Part of encapsulating data is to define classes as public, protected, or private. Each access specifier will encapsulate data differently.
Encapsulation in object modeling shows that an object’s internal operations are hidden from the rest of the program and that access to the object’s data is accessible through operations. Object modeling uses encapsulation because encapsulation is a principle of object-oriented design.
In English, polymorphism is “the condition of occurring in several different forms” (Fejér, A., 2020). A real-life example of polymorphism is having multiple characteristics, such as a person being a father, brother, uncle, and grandfather at the same time.
In programming, polymorphism occurs in inheritance where a child class can override a parent’s class methods to produce a tailored functionality. Suppose we have a parent class called Animal and two child classes called Cat and Dog. The parent class has a method called
animalSound(), and the child classes inherit that method from Animal. When we call the
animalSound() method using a Cat object, the sound is “meow” and “bark bark” when called using a Dog object. The act of overriding methods to have many forms is a form of polymorphism.
In object modeling, polymorphism is used in class diagrams to show inheritance where a child class inherits attributes and methods of a parent class.
Fejér, A. (2020). The general concept of polymorphism. Baeldung. https://www.baeldung.com/cs/polymorphism