OOPs (Object-Oriented Programming System)

An object is a physical thing, such a watch, computer, chair, table, pen, etc. Using classes and objects to construct a program is known as object-oriented programming. It makes program creation and maintenance easier by offering the following concepts:

  • Object
  • Class
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation

Apart from these concepts, there are some other terms which are used in Object-Oriented design:

  • Coupling
  • Cohesion
  • Association
  • Aggregation
  • Composition

Object

An object is any entity that possesses both state and behaviour. A chair, pen, table, keyboard, bike, etc. are a few examples. It could be intellectual or physical.An instance of a class can be defined as an object. An object takes up space in memory and has an address. It is possible for objects to interact without being aware of each other’s exact data or code. The kind of message accepted and the kind of response the objects return are the only requirements.

An example of an object would be a dog, which possesses traits like colour, breed, and so on, in addition to actions like eating, barking, and tail-wagging.

Class

A class is an object collection. It makes sense as an entity.

Another way to think of a class is as a blueprint from which you can make a unique item. There is no space needed for class.

Inheritance

Inheritance is the process by which an object picks up all of its parent object’s characteristics and actions. It allows for the reuse of code. It is employed to accomplish polymorphism at runtime.

Polymorphism

One activity carried out in multiple ways is referred to as polymorphism. To persuade the buyer in a different way, for instance, sketch a shape—a triangle, a rectangle, etc.

Polymorphism in Java is accomplished through the usage of overloading and overriding methods.

Another Example would be to speak; a dog would bark, a cat would meow, etc.

Abstraction

Abstraction is the process of displaying functionality while concealing core characteristics. We are unaware of the internal processing of phone calls, for instance.

Encapsulation

Encapsulation is the binding, or wrapping, of data and code into a single unit. Take a capsule, for instance; it is filled with several medications.

A Java class serves as an illustration of encapsulation. Since every member of the data is private in this case, the Java bean is the fully encapsulated class.

Coupling

The term “coupling” describes a class’s dependence on or knowledge of another class. It appears when students are conversant with one another. A class is strongly coupled if it possesses the details of another class. In Java, the visibility level of a class, method, and field can be shown using the private, protected, and public modifiers. Since there is no real implementation for the lesser coupling, you can use interfaces.

Cohesion

The degree to which a component completes a single, clearly defined task is referred to as cohesiveness. A highly coherent technique completes a single, well-defined task. The task will be divided into discrete segments via the weakly cohesive technique. The classes and interfaces in the java.io package, which are connected to input and output, make it a very cohesive package. However, because it contains disparate classes and interfaces, the java.util package lacks cohesiveness.

Association

The relationship between the things is represented by association. In this case, one thing may be connected to multiple objects. Four different kinds of associations between the things are possible:

  • One to One
  • One to Many
  • Many to One, and
  • Many to Many

Let’s use examples from real life to better grasp the link. For instance, a prime minister can have many ministers (one to many) and a country can have one prime minister (one to one). Many ministers can have multiple departments (many to many), while numerous MPs can have a single prime minister (many to one).

Both undirected and bidirectional associations are possible.

Aggregation

Association can be attained through aggregation. The relationship where one object includes other things as a portion of its state is represented by aggregation. It stands for the flimsy bond between items. In Java, it is also referred to as a has-a relationship. For example, inheritance is a symbol of the is-a relationship. It’s an additional method of reusing items. 

Composition

Association can also be attained through composition. The relationship where one thing incorporates other objects as a component of its state is represented by the composition. The dependent item and the enclosing object have a close relationship. It is the situation in which the objects it contains don’t exist on their own. All of the child objects will be automatically destroyed if the parent object is erased.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top