Double-chance functionIn software engineering, a double-chance function is a software design pattern with a strong application in cross-platform and scalable development. ExamplesComputer graphicsConsider a graphics API with functions to The double-chance function is an optimal method of creating such an implementation, whereby the first draft of the port can use the "fast to market, slow to run" version with a common One typical implementation in C++ could be: class CBaseGfxAPI {
virtual void DrawPoint(int x, int y) = 0; /* Abstract concept for the null driver */
virtual void DrawLine(int x1, int y1, int x2, int y2) { /* DrawPoint() repeated */}
virtual void DrawSquare(int x1, int y1, int x2, int y2) { /* DrawLine() repeated */}
};
class COriginalGfxAPI : public CBaseGfxAPI {
virtual void DrawPoint(int x, int y) { /* The only necessary native calls */ }
virtual void DrawLine(int x1, int y1, int x2, int y2) { /* If this function exists a native DrawLine
routine will be used. Otherwise the base
implementation is run. */}
};
class CNewGfxAPI : public CBaseGfxAPI {
virtual void DrawPoint(int x, int y) { /* The only necessary for native calls */ }
};
Note that the With this method it is, theoretically, possible to build an entire 3D engine (applying software rasterizing) using only one native function in the form of DrawPoint, with other functions being implemented as and when time permits. In practice this would be hopelessly slow, but it does demonstrate the possibilities for double-chance functions. References
|
Portal di Ensiklopedia Dunia