CPSC 410
Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern Learn the basics of Java Reflection
A methodology for software design to provide plugin-based extensibility Each application class (i.e. domain type) refers to (depends on) other application classes only through interfaces Classes use Factory to obtain references to dependencies
Concrete types of interfaces are decided by configuration files Allows the wrapper-oriented patterns to be applied at any time Wrapper-oriented patterns: ◦ Decorator ◦ Adaptor ◦ Proxy ◦ …
a class that provides methods which generally forwards responsibility for application- specific feature implementation to another object called the delegate has a delegate application-generic connector features are implemented by the delegator ◦ before forwarding to the delegate ◦ after forwarding to the delegate
extends Delegator implements the same interface as it’s delegate ◦ implements T where T is the type of the delegate acts as a transparent layer where connector features can be inserted example: AccountSecurityDecorator
extends Delegator implements a different interface as it’s delegate ◦ implements T where T is not the type of the delegate mediates between connector differences of T and the delegate type Example: AccountAdaptor
implements some application type T forwards responsibility for implementation of T over a network example: AccountRemoteProxy
Creates instances of an application type that are wrapped by any number of Delegators given in a configuration file Provides plug-and-play connector features without changing source code Forms the basis of extensibility features ◦ Eclipse Plugins ◦ Firefox plugins ◦ etc… example: SimpleDependencyInjectionFactory
the class for objects that represent Java classes part of the Java Reflection API ◦ helps implements programs that work on programs ◦ forms the basis for meta-programming in Java static Class forName(String name) ◦ get an object representing the class called name Object newInstance() ◦ automagically calls the no-arg constructor for the class and returns a new instance of the class
INPUT: ◦ A sequence of Java class names: C 0 … C n PRE-CONDITION: ◦ forall(C i ): i < n C i is a delegator for C i+1 IMPLEMENTATION: ◦ Use java.lang.Class to instantiate all C and link delegators to delegates OUTPUT: ◦ An instance of C 0