I am a Java beginner and I would appreciate it if someone here can explain how to implement Martin Fowler's plugin pattern in Java.
Thanks in advance.
I am a Java beginner and I would appreciate it if someone here can explain how to implement Martin Fowler's plugin pattern in Java.
Thanks in advance.
Simply, you define an interface for the operations you want to do, and pass an object at run time that implements that interface. So, for example, you might have communications through local shared memory and through remote TCP/IP. You build an interface, call it IConnection
that has send()
and recv()
, and then implement it in two classes, LocalConnection
and LongDistanceConnection
.
You then have some other class that needs to communicate, let's say TelephoneCall
.
To make a local call, you do
TelephoneCall call = new TelephoneCall(new LocalConnection());
To make a long distance call, you do
TelephoneCall call = new TelephoneCall(new LongDistanceConnection());
and the signature of the constructor is
public TelephoneCall(IConnection connect);