Object Oriented Modeling and Design 15CS55 Problem with implementation inheritance to the following problem? How Some of the inherited operations might exhibit unwanted behavior. What happens if the user calls Remove() instead of Pop()? MyStack List 1. Delegation +Push() Client +Pop() Remove() Add() +Top() 2. Interface inheritance Stack +Push() Client Remember this +Pop() structure!! +Top() MyStack List HerStack YourStack Delegation as alternative to Implementation Inheritance Delegation is a way of making composition (for example aggregation) as powerful for reuse as inheritance In Delegation two objects are involved in handling a request A receiving object delegates operations to its delegate. – The developer can make sure that the receiving object does not allow the client to misuse the delegate object Dept. of CSE, ACE Page 127
Object Oriented Modeling and Design 15CS55 Problem with implementation inheritance How to the following problem? Some of the inherited operations might exhibit unwanted behavior. What happens if the user calls Remove() instead of Pop()? 1. Delegation MyStack List Client +Push() Remove() +Pop() +Top() Add() 2. Interface inheritance Stack Client +Push() Remember this +Pop() structure!! +Top() MyStack List HerStack YourStack Delegation as alternative to Implementation Inheritance Delegation is a way of making composition (for example aggregation) as powerful for reuse as inheritance In Delegation two objects are involved in handling a request – A receiving object delegates operations to its delegate. The developer can make sure that the receiving object does not allow the client to misuse the delegate object Dept. of CSE, ACE Page 127
15cs55.docx