COMP 3350 Lecture Notes - Winter 2017 Lecture 21 - HSQLDB, Dependency injection, Common Interface

38 views3 pages

Document Summary

"services" are another way of looking at the component, of our system. A component provides a service to our application. Can coexist, switch over time, or switch at run-time. Prerequisite: multiple implementations of service must have a common interface. Gives us the loose coupling we need in order to replace the services with each other. Services are decoupled by separating out the interface from the implementation ("programming to interfaces") Select an implementation of a service at run-time. One will be the default, an alternative can be injected at run-time. Alternate service is a subclass of default, overriding behaviours, choose subclass at run-time. Alternate constructors accept a reference to another service. Controller allows you to change the service on the fly. void changeservice(servicei alt){ service = alt; eg. interface service{ void do(); public class servicecontroller implements service{ private service s; public void do(){ service. do(); In the sample project, dependency injection can be used to change the persistence implementation.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers