I have a top class, lets call it Car. I have an interface, lets call it ITyre and then I have two classes which implement ITyre. Lets call them Goodyear and Bridgestone.
Am I allowed to have a composition association between the interface ITyre and Car (from UML perspective, not a particular language)?
If you meant,
public class Car
{
ITyre something;
}
Yes, you can. In fact it will be good if you do it this way. So that your Car is not depending on any one particular concrete implementation. Your implementation here will give you flexibility to swap out tyres (DI or factory) irrespective of who built them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With