Composition And Inheritance

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

Object Composition and Inheritance are two techniques for reusing functionality in Object Oriented Systems. It is a fundamental activity of Software System Design to establish relation between two classes. They are Composition and Inheritance. There are two kinds of relationships, One is "is a" represents Inheritance, "has a" represents composition. A Class can have references to Objects of other classes as members in composition. Composition is better way to use where inheritance should not be used. For example if we inspired by someone we adobe the properties of that person and we have to add the quality of the person i.e. composition. But some quality of our parent automatically in us there is no need to strive i.e. inheritance. Composition is implemented simply by forwarding all calls to an Object Field. Composition more flexible, It is defined dynamically and not at compile time. Composition is late binding, we can change component dynamically. Object composition is defined at runtime, Object acquiring references to other objects. In such cases these objects will never be able to reach other protected data.There is ' no encapsulation break' in Object Composition. Inheritance is reuse technique, Object composition applied again and again in the design patterns.Composite is responsible for allocation and deallocation memory for an Object. In general, object composition should be favored over inheritance. It promotes smaller, more focused classes and smaller inheritance hierarchies.

Composition is easy to change behavior on dependency injection setters and getters. Composition is favored over Inheritance. Because in Java we can't extends more than one class. Composition also removes the ambiguity in other OOPs languages. Both Inheritance and Composition are different, In Composition we can refer some other class who hold the same properties; we can't reuse the code directly. In Inheritance we can inherit all super class properties into a sub class. So we can call super class properties from sub class Object. Inheritance is more rigid as most languages don't allow deriving from more than one class. For example B Class wants to expose the complete interface of Class A, such that Class B can be used wherever class A is expected, is called Inheritance. Class B want only some part of the behavior class A, indicates need for Composition. Composition is typically has a relationship, for ex: Person has Name. Inheritance uses is a relationship, for ex: Person is mammal.

Inheritance and limitations

It creates a strong relationship between two classes. Inheritance is also known as constructing a new class with already existed class features. Sharing the properties from one class (super) to another class (sub class) Java use extends keyword to provide inheritance between two classes. We can access the all super class properties from sub class Object. Inheritance creates a strong relationship between sub class and super class. Sub class must be aware of super class implementation details. Inheritance is useful when hierarchy represents is a relationship, and should be closed for modification. Inheritance creates an additional complexity, and more overused. In Inheritance we can't change the implementation at runtime, because inheritance defined at compilation time. Inheritance breaks encapsulation, because sub class exposes its super class implementation details. Inheritance is tight coupled, if any change in super class implementation will force to sub class to change.



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now