Time for action – injecting subtypes
Although creating a POJO can be an efficient way of creating simple classes, it can be limiting to have a concrete class definition scattered through the class definitions. It is a better design to use either an abstract class or an interface as the service type.
- Create a new interface in the
com.packtpub.e4.application
package, calledIStringService
. Define theprocess
method as abstract:public interface IStringService { public abstract String process(String string); }
- Modify the existing
StringService
so that it implements theIStringService
interface:public class StringService implements IStringService { ... }
- Modify the reference in the
Rainbow
class to refer to theIStringService
interface instead of the ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.