[Cs3] Inheritance vs object instance for adapters

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Nov 3 15:57:46 EST 2014


> 
> I am emailing regarding what we discussed in class about the benefits of
> inheriting from an adaptee vs. just creating an instance of it in the
> adapter.

So, here is the comparison. 

- the class adapter relies on multiple inheritance (not available on
  all languages); the relationship between classes is somewhat static
  (codified in specification of inheritance) but clearer.

- the object adapter uses aggregation. So the adaptee may potentially
  has a different lifetime (for example, may be instantiated
  later). Or the adapter may point to different adaptees during
  run-time.

In general, in OOP, there is a trend of moving from inheritance-based
designs to composition-based designs as more flexible.

Thanks,
-- 
Mikhail


More information about the cs3 mailing list