Lecture 15 Factories and Frameworks

Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Copyright W.E. Howden 1 Lecture 16: Factories and Frameworks Copyright W.E. Howden 2 Factory Pattern One definition: Involves a class that is used to create instances of one or more other classes. e.g. it will contain methods like: A: getInstanceofA() which will create and return an instance of type A Copyright W.E. Howden 3 Factory Motivation 1 Why not just use the constructor for A? A is typically an interface or abstract class ii) Actual concrete class may not be known until runtime, via a run time property, and will be determined by the getInstanceA() method iii) Concrete class known during class reuse iv) Except for the factory, the code does not have to know what the concrete class is Copyright W.E. Howden 4 Creator Pattern (Review) Give class B the responsibility of creating instances of class A if: B aggregates object instances of A B contains objects of class A B records instances of objects of class A B closely uses objects of class A B has the initialization data that will be passed to an object of class A when it is created Copyright W.E. Howden 5 Factory Motivation 2 Why not just put the getInstanceA() code in the places where the Creator pattern suggests such an object should be created? This code will have the details of what the concrete class looks like or how you get it. Could have poor cohesion since the code is built around using an object with interface/abstract supertype A, and the details do not belong here Copyright W.E. Howden 6 Factories vs Singleton Singleton pattern: returns the single instance of a class Is this an example of a factory? Sort of, but not really the class of the returned instance is known in the code requesting it as a concrete class, not an interface or abstract class the class of the returned instance is the same class as the place where the getInstance() method is located, it is not an instance of a different class Copyright W.E. Howden 7 DS Factory Example Involves the use of a proxy class for the DataBase subsystem interface First a review of some Java features Copyright W.E. Howden 8 Java Review Properties Objects A Property object holds a set of string pairs where the first is a key and the second is a property associated with that key. (Subclass of HashTable class.) A.getProperty(s) will return the string that is associated with the key s in the Properties object A A.setProperty(s, t) will set create a property s with value t in the Property object A Copyright W.E. Howden 9 Java Review System Class the System class special class with static methods e.g. System.out will return the standard output device, as used in System.out .printline(x) to print out the string value of x System.getProperties() will return a properties object that contains configuration information....
View Full Document

Page1 / 36

Lecture 15 Factories and Frameworks - Copyright W.E. Howden...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online