Generation Gap By Kurt Rehwinkel Generation Gap n
Generation Gap By Kurt Rehwinkel
Generation Gap n Introduction – What is the Generation Gap? n n The author describes it as a pattern. It is potentially as much a strategy as much as a pattern
Generation Gap: Intent n n Support for auto-generation and regeneration of source code by software development tools. To modify or extend generated code such that the regeneration of the source does not effect the implementation.
Generation Gap: Applicability n n Code is generated automatically. Generated code is encapsulated. Regenerated code retains form in interface and instance variables. Generated classes do not tend to be integrated into inheritance hierarchies. To do so requires the ability to specify super-classes and may require multiple inheritance support in the language.
Generation Gap: Participants n Core. Class n n Extension. Class n n Abstract class containing tool generated implementation. Never modified by hand. Written and/overwritten by the software development tool. A trivial subclass of Core. Class. Provides concrete implementations and extends or overrides the behavior in the Core. Class. Preserves developer generated software implementations. Client n Instantiates and refers ONLY to Extension. Class.
Generation Gap: Structure
Generation Gap: Example class Clock_core { public: Clock_core(const char*); protected: Interactor* Interior(); virtual void Set. Time(); virtual void Set. Alarm(); virtual void Snooze(); class Clock : public Clock_core { public: Clock(const char*); void Run(); virtual void Set. Time(); virtual void Set. Alarm(); virtual void Snooze(); virtual void Update(); private: void Get. System. Time(int& h, int& m, int& s); void Set. System. Time(int h, int m, int s); void Alarm(); protected: Picture* _clock; SF_Polygon* _hour_hand; SF_Rect* _min_hand; Line* _sec_hand; private: float _time; float _alarm; }; };
Generation Gap: Consequences n The Good n n n The Bad n n n Modifications/Implementations are decoupled from generated code. Core. Class and Extension. Class may be developed and tested independantly. Doubles the number of classes. Changes to interfaces in the tool must be reflected in the Extension. The Ugly n Integration into inheritance may be difficult.
Generation Gap: Related Pattern n Use of other patterns such as Template Method, Factory methods, or Strategy Patterns may serve to make generated code more flexible and reusable.
- Slides: 9