Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

0

An abstract class and template pattern should be used to do this. You mentioned that there will be a multiple-inheritance problem in your design. But is there anything stopping you follow the principle, "Inherit the most important class and delegate the rest" to solve this? Just delegate the task to another abstract class that does things you mentioned in "...


1

I think the problem is your outlook on component-based design, not the lack of a design pattern to support this outlook. The purpose of a Java interface is to define the programmer's interface to the components that implement it. The user of your object will only have access to public members of the object, so making something non-public in an interface ...


1

To continue off of what @Hans said, you can't reasonably tests every situation for this ordering issue and it might be buggy on certain situations. But there is something you can do, you could put an assert in main code to make sure it is "in order", if it is not too expensive. There are certain situations where this is acceptable, e.g. if the list is not "...


3

Yes, it is correct, but not optimal. The dependency just says 'A2Impl' cannot do without 'A', but that is obvious, since A2Impl implements A. In fact, the 'implements' relationship implies the dependency. If A2Impl has a permanent reference to another instance of A, it would be better to replace the dependency by an association (an arrow with a solid line ...


1

This is a classic scenario where it helps to separate the client API from the service provider interface (SPI). Your SPI should be an interface that is easy for providers to implement, so it will likely have just one method that sends an email: public interface EmailServiceSpi { void sendEmail(String recipient, EmailContext context); } Your client API ...


1

If it was me, along with Alex answer here, I would have segregated interface into more granular level so that ISP (Interface Segregation Principle) is not violated. public interface EmailFactory { Email createInvitation(Payload payload); Email createNotification(Payload payload); Email createPasswordReset(User user); Email createValidator(...


Top 50 recent answers are included