Say I was using a library for shapes which offered:
class Shape
class Circle extends Shape
class Square extends Shape
but I want introduce the concept of red shapes. I cannot modify the library but I can create:
class RedShape extends Shape
however this cannot be easily extended to RedCircle
as it cannot extend both RedShape
and Circle
.
I don't think the decorator pattern quite works here but is there a technique for achieving this?