






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the singleton and adapter patterns from the book 'design patterns' by anton roukhline, john setzer, and jingfeng yu. The singleton pattern ensures a class has exactly one instance and provides global access to it. The adapter pattern makes interfaces compatible. Examples, class diagrams, and benefits of each pattern.
Typology: Study notes
1 / 12
This page cannot be seen from the preview
Don't miss anything!







n Pages 127-134 in Design Patterns
Printer 1 Printer 2 Printer 3 Printer 4
Print Spooler
public class Singleton { private static Singleton instance; private Singleton() {} public static Singleton getInstance() { if (instance ==null) { instance = new Singleton(); } return instance; }
n Pages 139-150 in Design Patterns
class Adapter extends Quadrilateral {
public Adapter() {} // draw is an abstract method in class Quadrilateral public draw ( point1, point2, point3, point4) { bottomLeftCorner = point1; sideLength = point2.x – point1.x; Square.draw(bottomLeftCorner, sideLength); }
public query(table, column, target) { … // initialize table connection here or preferably in a constructor … resultSet = Statement.executeQuery( “SELECT ” + target + “ FROM ” + table+ “ WHERE “ + column+ ” = “ +target+ ”;” ); … list = resultSet.toList(); return list; }