1 / 9

Roadmap

Roadmap. Generics Abstract Factory Annotations Model-Driven Engineering. Design Patterns, a preview…. “Each pattern describes a problem which occurs over and over again in our environment; and it describes the core of the solution to that problem, in such a way that

karsen
Download Presentation

Roadmap

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. P2 — Clients and Servers Roadmap • Generics • Abstract Factory • Annotations • Model-Driven Engineering

  2. P2 — Clients and Servers Design Patterns, a preview… “Each pattern describes a problem which occurs over and over again in our environment; and it describes the core of the solution to that problem, in such a way that you can use this solution a million times over…” — Christopher Alexander

  3. P2 — Clients and Servers Creational Patterns … deal with the best way to create objects

  4. P2 — Clients and Servers Abstract Factory Pattern • A Factory is the location in the code at which objects are created. • Provides an interface for creating families of related dependent objects. • Let clients create products in any family of products in an abstract way, without having to specify their concrete class. • Separates the details of implementation of a set of objects from its general usage.

  5. ConcreteFactory1 createProduct() ConcreteFactory2 createProduct() P2 — Clients and Servers Structure of the Abstract Factory Pattern AbstractFactory createProduct() Client AbstractProduct concreteProduct

  6. P2 — Clients and Servers Abstract Factory with Generics: Ludo Example package ludo; // NOTE interface for "Abstract Factory" pattern. public interface Factory<T> { public T createInstance(); }

  7. P2 — Clients and Servers The Concrete Factory package ludo; public class LudoFactory implements Factory<Ludo> { … public Ludo createInstance() { initializeHome(); initializeBranchings(); initializeMainRing(quarterLength); initializeHomeRuns(quarterLength); initializeNests(); return new Ludo(nest); } … We specify the type to be Ludo

  8. «interface» AbstractFactory createInstance() : T «interface» Board addPlayer(Player ) … LudoFactory createInstance() : Ludo Ludo P2 — Clients and Servers The Ludo Example

  9. P2 — Clients and Servers The Client drives the Ludo Game The Driver can drive any Board game public class Driver implements Runnable { private Board board; public Driver(Factory<? extends Board> factory) { this.board = factory.createInstance(); board.addPlayer(new Player()); board.addPlayer(new Player()); board.addPlayer(new Player()); } … We specify the Game Factory we want public class Main { public static void main(String[] args) { Runnable gameDriver = new Driver(new LudoFactory()); gameDriver.run(); }

More Related