What is the composition of the inheritance?

The composition of the inheritance is the programming methodology, which is used in object -oriented programming languages, which helps to establish a more dynamic and variable relationships between objects in the application. The basic format for the composition of the inheritance is to include an instance of the object inside another object. This is clearly different from an object -oriented heredity method, but can serve the same purpose in many models. The advantages of components over inheritance include a well -defined boundary between composting objects and packaging objects, the ability to change the implementation of the object without affecting the entire hereditary hierarchy, and the less restrictive framework for the initial program design. However, some complications could include problems with serialization and too complex structures in large established programs.

In the Orientued Programming object, one of the features that is important to determine during the design is how to doé objects relate to each other. Inheritance is a central mechanism in object -oriented programming and allows one object to inherit all data and methods of its parent, which can then add, modify or expand their own implementation. An example of an inheritance -based design could be with a program that has one main class that defines them and models some general attributes of all cars. The class for each individual brand of the car is then manufactured as a descendant of the main class, but defines specific information, such as engine size, fuel capacity or other information specific to the specific brand of the car.

The composition is expressed by the inclusion of instances of objects in other objects. If there is a main class that defines a general car, then instead of creating a subclasses for specific car brands, the main class could instead contain cases of other objects that you determine the car more specifically. This could mean that the main class of the car couldDating an object for the engine type and one for fuel capacity that would be set when the class is used to create an instance of a particular brand of a car.

When composing above the legacy of objects contained in the main class, they are not directly related to the main class, which gives developers the freedom to change the way the individual objects work. A problem that can help prevent inheritance is a situation where the inheritance tree can be too deep, which means that any class adjustment in the tree could require changes in the tree length. Not all object -oriented languages ​​have support for more heritage and composition over heritage is a method that can be used to resolve this restriction.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?