module Context # This is the abstract view class class View attr_reader :context def initialize(context) @context = context end def addView(view) myWidget = getWidget() if(myWidget != nil) newWidget = view.getWidget() if !newWidget.nil? myWidget.add(newWidget) newWidget.addedTo(myWidget) end end end def removeView(view) myWidget = getWidget() if(myWidget != nil) oldWidget = view.getWidget() if !oldWidget.nil? myWidget.remove(oldWidget) oldWidget.removedFrom(myWidget) end end end # Concrete classes should override this method def open end # Concrete classes should override this method def close end # Concrete classes should override this method def getWidget return nil end def notifyKey(widget, key) @context.notifyKey(self, key) end end end