CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector...
-
Upload
sharlene-griffith -
Category
Documents
-
view
217 -
download
0
Transcript of CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector...
![Page 1: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/1.jpg)
CPSC 410
![Page 2: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/2.jpg)
Build on previous Connector lectures
Learn how to implement flexible connector implementations
Learn the Dependency Injection pattern
Learn the basics of Java Reflection
![Page 3: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/3.jpg)
![Page 4: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/4.jpg)
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
![Page 5: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/5.jpg)
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◦ …
![Page 6: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/6.jpg)
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
![Page 7: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/7.jpg)
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
![Page 8: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/8.jpg)
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
![Page 9: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/9.jpg)
implements some application type T
forwards responsibility for implementation of T over a network
example: AccountRemoteProxy
![Page 10: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/10.jpg)
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
![Page 11: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/11.jpg)
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
![Page 12: CPSC 410. Build on previous Connector lectures Learn how to implement flexible connector implementations Learn the Dependency Injection pattern.](https://reader035.fdocuments.us/reader035/viewer/2022062516/56649e605503460f94b5b427/html5/thumbnails/12.jpg)
INPUT:◦ A sequence of Java class names: C0 … Cn
PRE-CONDITION:◦ forall(Ci): i < n
Ci is a delegator for Ci+1
IMPLEMENTATION:◦ Use java.lang.Class to instantiate all C and link
delegators to delegates OUTPUT:
◦ An instance of C0