From: "Sean O'Dell" Date: 2003-09-04T04:03:27+09:00 Subject: Re: OOP flavors - was Re: Python vs. Ruby Ged Byrne wrote: > [...snip...] > > Good OO involves separating all of these views so that > it is possible for somebody using the objects to work > consistantly within a single model of a real world > object. [...snip...] > When your dialog receives a repaint command, it says > "Button, here is some canvas. Draw yourself upon it." > [Button.paint(g)] The button takes this canvas and > breaks it into 5 parts, passes each part to the > necessary shape and tells them to draw themselves. > > Finally the chain comes to a Rectangle or Rhombus > object. This shape object does not know that it is > part of a button. It only knows that it is a shape > and how to draw itself upon a canvas. > > Eventually a canvas will be given a command. Whether > it is Canvas.draw(Rectangle) or Canvas.plot(x,y) > depends on the canvas object. Can it just plot > points, or does it know how to draw geometric shapes. > What you wouldn't expect the Canvas to know is how to > draw a button or a dialog. > > In this model you are dealing with a button as a group > of geometric shapes. > > When you use a dialog that has a button on it, you > don't worry about any of this. You say "Dialog, you > have a button called Fred." "Fred, when somebody > clicks on you, do this." > > You are working in a logical model that views a button > as something on dialog that causes an action when it > is pushed. > > So whether or not you say Window.draw(Square) or > Square.draw(Window) depends upon the logical model you > are dealing with. OO design does not dictate one form > over the other. OO design dictates a systematic > modeling of reality. This is an excellent example! The button itself is thought of as a solid object (physical) and knows how to do several things with itself; it knows how it is supposed to look, how to react to button clicks, etc. It encapsulates this: a button. Perfectly. By contrast, a string does not encapsulate a solid object; it encapsulates information. Therefore, a string is not expected to render itself on a canvas. It all has to do what with you are modelling. Are you modelling a solid-object-abstraction? If so: button.draw(canvas) button.click() button.hide() Or is button just a shape, and not modelled after a solid object? If so: canvas.draw(button.polygon) I really like your analogy. I have written, myself, many custom UI controls and have come to understand the very class system you're describing. Sean O'Dell