CSC/ECE 517 Fall 2007/wiki2 10 cv: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 8: Line 8:


===<b>Advantages and Disadvantages of Inheritance</b>===
===<b>Advantages and Disadvantages of Inheritance</b>===
Advantages of Inheritance: <br>
<b>Advantages of Inheritance:</b> <br>
- Straightforward to use <br>
- Straightforward to use <br>
- Supported by many programming languages <br>
- Supported by many programming languages <br>
- Easy to implement new functionality <br>
- Easy to implement new functionality <br>


Disadvantages of Inheritance: <br>
<b>Disadvantages of Inheritance:</b> <br>
- Exposes a subclass to the details of its parent class <br>
- Exposes a subclass to the details of its parent class <br>
- Changes in the parent class implementation would cause the subclass to change as well <br>
- Changes in the parent class implementation would cause the subclass to change as well <br>
Line 21: Line 21:


===<b>Advantages and Disadvantages of Delegation</b>===
===<b>Advantages and Disadvantages of Delegation</b>===
Advantages of Delegation: <br>
<b>Advantages of Delegation:</b> <br>
- Provides flexibility due to the fact that any object can be replaced at run time by another one of the same type <br>
- Provides flexibility due to the fact that any object can be replaced at run time by another one of the same type <br>


Disadvantages of Delegation: <br>
<b>Disadvantages of Delegation: </b><br>
- Is efficient since objects are encapsulated <br>
- Is efficient since objects are encapsulated <br>



Revision as of 04:39, 23 October 2007

Inheritance vs. delegation. Follow the debate on inheritance vs. delegation. Construct (or, better, cite) examples that show cases where inheritance is better, and cases where delegation is better. Attempt to characterize the situations in which you should employ one or the other.


Inheritance

Inheritance is a way to form new classes in object oriented programming using already defined classes. Inheritance is used to help reuse code that already exists with little or no modifications and this is one of the advantages of using inheritance since it helps reduce the complexity of a program. MAny programmers are confused on when to use inheritance but inheritance is mainly used when a programmers new class can be used in place of the existing class and the relationship between them can be described as an is-a relationship.

Advantages and Disadvantages of Inheritance

Advantages of Inheritance:
- Straightforward to use
- Supported by many programming languages
- Easy to implement new functionality

Disadvantages of Inheritance:
- Exposes a subclass to the details of its parent class
- Changes in the parent class implementation would cause the subclass to change as well

Delegation

Delegation is when one object relies on another object in order to provide a specified set of functionalities and this is sometimes referred to as aggregation, consultation, or forwarding. It is better to use delegation when a programmers new class needs to use the existing class and the relationship can be described as a has-a or uses-a relationship.

Advantages and Disadvantages of Delegation

Advantages of Delegation:
- Provides flexibility due to the fact that any object can be replaced at run time by another one of the same type

Disadvantages of Delegation:
- Is efficient since objects are encapsulated


References

Inheritance vs. Delegation
Practices of an Agile Developer