GithubHelp home page GithubHelp logo

myheyj / et-plus-plus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binshengliu/et-plus-plus

0.0 0.0 0.0 581 KB

ET++ is used to study the Design Patterns book of GOF

License: Other

C++ 19.48% C 75.40% Makefile 5.12%

et-plus-plus's Introduction

Patterns introduced in Design Patterns

ET++ is referenced in Abstract Factory (p97), Builder, Factory Method, Prototype, Adapter, Bridge (p151), Composite, Decorator, Facade, Flyweight, Chain of Responsibility, Command, Iterator, Mediator, Observer, and Strategy in Design Patterns (ISBN-13: 9787111095071).

Abstract Factory

Factories:

  • WindowSystem (abstract)

    • NeWSWindowSystem

    • ServerWindowSystem

    • SunWindowSystem

    • XWindowSystem

Products:

  • WindowPort (abstract)

    • NeWSWindowPort

    • ServerPort

    • SunWindowPort

    • XWindowPort

  • FontManager (abstract)

    • NeWSFontManager

    • ServerFontManager

    • SunFontManager

    • XFontManager

  • DevBitmap (abstract)

    • SunBitmap

    • XBitmap

  • ClipBoard (abstract)

    • SunClipBoard

    • XClipBoard

How does et++ decide which concrete factory to use?

In InitWindowSystem, it uses macros to choose the concrete factory.

WindowSystem    *gWindowSystem= 0;

void InitWindowSystem()
{
    // ...

#ifdef WS_SUNSERVER
    if (gWindowSystem == 0)
	gWindowSystem= NewServerWindowSystem(); // try to connect to SunWindow server
#endif WS_SUNSERVER

#ifdef WS_X
    if (gWindowSystem == 0)
	gWindowSystem= NewXWindowSystem();      // try to connect to X server
#endif WS_X

#ifdef WS_NEWS
    if (gWindowSystem == 0)
	gWindowSystem= NewNeWSWindowSystem();   // try to connect to NeWS server
#endif WS_NEWS
    
#ifdef WS_SUNWINDOW
    if (gWindowSystem == 0)
	gWindowSystem= NewSunWindowSystem();    // try SunWindow System
#endif WS_SUNWINDOW
    
    // ...
}

Bridge

  • BlankWin (Abstraction)

    • Window (Refined Abstraction)

    • Icon (Refined Abstraction)

  • WindowPort (Implementor)

    • NeWSWindowPort (Concrete Implementor)

    • ServerPort (Concrete Implementor)

    • SunWindowPort (Concrete Implementor)

    • XWindowPort (Concrete Implementor)

This pattern is combined with Abstract Factory to make a concrete WindowPort object.

class WindowPort *BlankWin::MakePort()
{
    if (portDesc == 0) {
        portDesc= gWindowSystem->MakeWindow((InpHandlerFun) &BlankWin::input, this,
                        TestFlag(eBWinOverlay), TestFlag(eBWinBlock), FALSE);
        portDesc->cursor= cursor;
    }
    return portDesc;
}

et-plus-plus's People

Contributors

liubinsheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.