Control class (Controller) Inheritance, controller inheritance
In the control class, Controller is only a base class, mainly used to trigger messages transmitted from the window and process different message responses in a dictionary. In Python, there is a dictionary without a case statement. For many messages, it is easier to process message calling functions by using a dictionary. When receiving a message, you can first determine whether the message is in the dictionary. If yes, it indicates that the message already has a corresponding response function. If not, it indicates that the message is processed by the default function in the window. It is processed in dictionary mode. From the code writing perspective, it saves a lot of code than the case statement. You may see that many messages in this base class do not have clear message processing, but only fill in the pass statement. That is to say, these functions are not implemented, but they are only a placeholder. What is the significance of this writing? In fact, writing in this way is equivalent to a virtual function in C ++. as long as these functions are reloaded in the derived class, the corresponding functions can be called. The purpose of this design is to allow the control class to write different functional code for use in different scenarios, so as to achieve code reuse of the base class. The specific message processing code of the derived class is as follows:
# Developer: Cai junsheng (QQ: 9073204) Shenzhen 2014-9-24 # control class CtrlAll (Controller): def _ init _ (self): Controller. _ init _ (self) # call the base class constructor self. model = Model () self. view = View () self. win = Window (self. getWnd () def OnPaint (self, wParam, lParam): paint = PaintCanvas (self. getWnd () self. view. paint (paint, self. model. getPoint () return True def OnMouseMove (self, wParam, lParam): paint = UpdateCanvas (self. getWnd () pt = self. getPoint (lParam) if self. win. isLButton (wParam): self. model. addPoint (pt. x, pt. y, False) self. view. moveTo (paint, pt. x, pt. y, True) else: self. view. printPos (paint, pt. x, pt. y) return True def OnLButtonDown (self, wParam, lParam): self. win. captureMouse () paint = UpdateCanvas (self. getWnd () pt = self. getPoint (lParam) self. view. moveTo (paint, pt. x, pt. y, False) self. model. addPoint (pt. x, pt. y, True) return True def OnLButtonUp (self, wParam, lParam): self. win. releaseMouse () return True
In the constructor of a derived class, the constructor of the base class is called to initialize the constructor, and then the model class and View class are created. In this way, the control class can communicate with the model class and View class.
OnPaint is a message that responds to window updates. Therefore, it calls the update window interface in the View class.
OnMouseMove is the response when the mouse moves. Here, the model class is called to save the corresponding data and the View class is called to display the corresponding mouse coordinates on the interface.
The OnLButtonDown function is a member function that captures the mouse and obtains the coordinates of the mouse. The current position of the mouse is displayed on the interface, finally, save the corresponding mouse coordinates to the model class.
The OnLButtonUp function is a member function that plays the message response with the left mouse button. It is relatively simple, but only removes the Mouse capture.
Question about connecting viewController in storyboard to View Controller of its class in ios development
I think you're a little confused... I usually connect to one interface instead of writing them together.
How to define a Base_Controller to inherit other controllers?
I can't find it all the time. It is definitely not supported. Please read the manual carefully for details?