De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

OOS Object geOrienteerd Software-ontwerp - 4 Codeerperikelen Singleton Specificeren Scheiding GUI en Domein Facade.

Verwante presentaties


Presentatie over: "OOS Object geOrienteerd Software-ontwerp - 4 Codeerperikelen Singleton Specificeren Scheiding GUI en Domein Facade."— Transcript van de presentatie:

1 OOS Object geOrienteerd Software-ontwerp - 4 Codeerperikelen Singleton Specificeren Scheiding GUI en Domein Facade

2 Codeerperikelen

3 KlasB KlasA 1 0,1 class KlasA { private KlasB b; public KlasA() {} public void setB(KlasC c) { this.b = new KlasB(this,c); } class KlasB { private KlasA a; private KlasC c; KlasB(KlasA a, KlasC c) { this.a = a; this.c = c; } 2-richtingsnavigatie KlasC 1

4 KlasB KlasA 1 1 class KlasA { private KlasB b; public KlasA(KlasC c) { b = new KlasB(this, c); } } class KlasB { private KlasA a; private KlasC c; KlasB(KlasA a, KlasC c) { this.a = a; this.c = c; } } 2-richtingsnavigatie KlasC 1

5 Onderdeel Container  class Container { private Collection onderdelen; public Container() { onderdelen = new ArrayList(); } public void addOnderdeel(Object o) { onderdelen.add( new Onderdeel(o) ); } class Onderdeel { private Object o; Onderdeel(Object o) { this.o = o; } mogelijke implementatie Object 1

6 class Verzameling { private Collection elementen; public Verzameling() { elementen = new ArrayList(); } public void addElement(int i) { elementen.add(new Element(i)); } class Element { private int _x; Element(int x) { _x = x; } int getInt() { return _x; } } } Element Verzameling  x : int

7 Singleton Patroon

8 Singleton-patroon een klasse waarvan we maar 1 enkel object kunnen maken/krijgen. verschillende gebruikers willen met hetzelfde object communiceren. bijvoorbeeld: registratieklasse klasse voor database-toegang

9 Voorbeeld van Singleton let op onderstreping public class RegistratieVanX { private Collection xjes; private static RegistratieVanX singleton = new RegistratieVanX(); private RegistratieVanX() { xjes = new ArrayList(); } public static RegistratieVanX getSingleton() { return singleton; }... }

10 Specificeren

11 Specificatie van methoden Tussen header en body /* pre: dat wat geldt voor aanroep post: dat wat geldt na aanroep */ Contract: gebruiker van methode: let op pre-conditie implementator: houdt zich strikt aan pre- en post condities.

12 Voorbeeld van contract class Klantenregistratie { private Collection klanten; /* pre: naam is niet de lege string post: terugkeerwaarde is de collectie klanten waarvan de klantnaam begint met naam ongeacht hoofd/kleine letters; elke klant die voldoet komt hierin eenmaal voor. */ public Collection zoekKlant(String naam){ String nm = naam.toLowerCase(); ArrayList lijst = new ArrayList(); Iterator it = klanten.iterator(); while (it.hasNext()) { Klant klant = (Klant)it.next(); if ( klant.getNaam().toLowerCase().startsWith(nm)) lijst.add(klant); } return lijst; } }

13 javadoc /** pre: wanneer is aanroep toegestaan post: wat is er gewijzigd uitzonderingen: wanneer ontstaan welke excepties */ voorafgaand aan declaratie methode Zie: http://java.sun.com/j2se/javadoc/writingdoccomments/index.htmlhttp://java.sun.com/j2se/javadoc/writingdoccomments/index.html

14 Example (Sun) /** * Returns an Image object that can then be painted on the screen. * The url argument must specify an absolute {@link URL}. The name{@link URL} * argument is a specifier that is relative to the url argument. * * This method always returns immediately, whether or not the * image exists. When this applet attempts to draw the image on * the screen, the data will be loaded. The graphics primitives * that draw the image will incrementally paint on the screen. * @param url an absolute URL giving the base location of the image@param * name the location of the image, relative to the url argument * @return the image at the specified URL@return * @see Image@see */ public Image getImage(URL url, String name) { try { return getImage(new URL(url, name)); } catch (MalformedURLException e) { return null;} }

15 getImage public Image getImage(URL url,ImageURL String name)String Returns an Image object that can then be painted on the screen. The url argument must specify an absolute URL.URL The name argument is a specifier that is relative to the url argument. This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen. Parameters: url - an absolute URL giving the base location of the image name - the location of the image, relative to the url argument Returns: the image at the specified URL See Also: Image

16 Scheiding GUI en Model

17 klasse  object  view Dobbelsteen int ogen Dobbelsteen( ) int getOgen( ) void gooi( ) : Dobbelsteen ogen = 5 ogen 5 Microsoft Windows XP [versie 5.1.2600] (c) copyright 1985-2001 Microsoft Corp. c:\>aantal ogen is 5 user interface 1 modelobject 4 UI-objecten

18 scheiding model en view Dobbelsteen int ogen Dobbelsteen( ) int getOgen( ) void gooi( ) ViewOpDobb 1 * *

19 Observerpatroon Dobbelsteen int ogen Dobbelsteen( ) int getOgen( ) void gooi( ) void attach(ViewOpDobb) void detach(ViewOpDobb) void inform( ) ViewOpDobb void update( ) 1 * *

20 Facadepatroon

21 Facade ontwerppatroon

22

23 To do ontwerp facade pas het singleton-patroon toe voor de facade voor de meer ingewikkelde methoden: pre/post condities schrijven; conform javadoc in de code aanbrengen. codeer alle domeinklassen incl facade


Download ppt "OOS Object geOrienteerd Software-ontwerp - 4 Codeerperikelen Singleton Specificeren Scheiding GUI en Domein Facade."

Verwante presentaties


Ads door Google