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.
精彩评论