It measures the strength of the relationship between the module and data. In OOP, cohesion refers to the degree to which the elements inside a module belong together. Since using loose coupling is always a good habit. The reuse of code is difficult in tight coupling because we cannot separate the code. It creates conditions where modifying the code of one object also requires changing the code of other objects. Objects that depend on other objects and can modify the states of other objects are called tightly coupled. Loose coupling makes the code more flexible, changeable, and easier to work with. Objects that are independent of one another and do not directly modify the state of other objects is called loosely coupled. There are two types of coupling, loose coupling, and tight coupling. It defines how closely two objects are connected together. It means that an object cannot directly change or modify the state or behavior of other objects. In programming, separation of concerns is known as coupling. The following figure best illustrates the class and object in OOP.Īpart from these core concepts, there are some other object-oriented concepts used in OOP. Note that a class can exist without an object but vice-versa is not possible. Note that classes are not considered as a data structure. it binds data and functions together in a single unit. Inside a class, we define variables, constants, member functions, and other functionality. ClassĪ class is a blueprint or template of an object. Different objects have different states or attributes, and behaviors. It contains member functions, variables that we have defined in the class. It is referred to as an instance of the class. OOPs ConceptsĪn object is a real-world entity that has attributes, behavior, and properties. A person plays an employee role in the office, father and husband role in the home. The above figure best describes the concepts of polymorphism. It allows the developer to create clean, sensible, readable, and resilient code. It allows us to create methods with the same name but different method signatures. The word polymorphism is derived from the two words i.e. The concept allows us to inherit or acquire the properties of an existing class (parent class) into a newly created class (child class). A class is the best example of encapsulation. It protects data and functions from outside interference and misuse. There are the following advantages of abstraction:Įncapsulation is a mechanism that allows us to bind data and functions of a class into an entity. Using the concept developer can easily make changes and added over time. The concept allows us to hide the implementation from the user but shows only essential information to the user. There are four pillars on which OOP rests. The major concepts that we have discussed above are known as pillars of OOPs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |