accessible globally in an application. -Ensure unique instance -Access instance controlled way -Define a value shared by all system Samstag, 24. November 12
Line implements Shape { public void draw() { System.out.println("line"); } } class Square implements Shape { public void draw() { System.out.println("square"); } } class Circle implements Shape { public void draw() { System.out.println("circle"); } } Samstag, 24. November 12
public void windowOpened(WindowEvent e); public void windowIconified(WindowEvent e); public void windowDeiconified(WindowEvent e); public void windowActivated(WindowEvent e); public void windowDeactivated(WindowEvent e); public void windowClosing(WindowEvent e); } public class WindowAdapter implements WindowListner{ public void windowClosed(WindowEvent e){} public void windowOpened(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowClosing(WindowEvent e){} } Samstag, 24. November 12
unified or general interface. -Make an entry point to your subsystems. -Minimize communication and independency -Security and performance considerations Samstag, 24. November 12
Special extends General { public void accessSpecial(); } interface Private extends General { public void accessPrivate(); } class GeneralInfo implements General { public void accessGeneral() { ! //... } //... } Samstag, 24. November 12
throw new Exception(); if (user is general) return new GeneralInfo(); if (user is special) return new SpecialInfo(); if (user is executive) return new PrivateInfo(); //... } Samstag, 24. November 12
med; BtnPrevious(ActionListener al, Mediator m) { super("Previous"); addActionListener(al); med = m; med.registerPrevious(this); } public void execute() { med.previous(); } } class LblDisplay extends JLabel{ Mediator med; LblDisplay (Mediator m) { super("0",JLabel.CENTER); med = m; med.registerDisplay(this); setBackground(Color.white); setBorder(new EtchedBorder(Color.blue, Color.green)); Font font = new Font("Arial",Font.BOLD,40); setFont(font); } } Samstag, 24. November 12
void throwit() { show.setForeground(Color.black); int num = (int)(Math.random()*6 +1); int i = counter++; list.add(i, new Integer(num)); undo.add(i, new Memento(num)); show.setText(""+num); } Samstag, 24. November 12
args) { System.out.println("Enter Text >"); // create an event source - reads from stdin final EventSource eventSource = new EventSource(); // create an observer final ResponseHandler responseHandler = new ResponseHandler(); // subscribe the observer to the event source eventSource.addObserver(responseHandler); // starts the event thread Thread thread = new Thread(eventSource); thread.start(); } } Samstag, 24. November 12
missing features of a given programming language (Java or C++ for instance). Peter Norvig demonstrates that 16 out of the 23 patterns in the Design Patterns book (that is primarily focused on C++) are simplified or eliminated (via direct language support) in Lisp.. Moreover, inappropriate use of patterns may unnecessarily increase complexity Samstag, 24. November 12