Original Post
WARNING-- This isn't ground breaking by any stretch of the imagination, just a different perspective on a common problem. (And if the Bold bugs you I apologize -- Sometimes its hard to get stuff read without making it easy for people ;) So I was getting ready to start developing some tools for an upcoming project, and it was time to work on the GUI. (This is not a discussion about reinventing the wheel). I like working on GUI's because there are so many implicit relationships between objects, I always feel like my Object-Oriented Muscles are getting flexed. Designing a class layout that is easy to work with is the number one concern, but right after that comes ease-of-implementation. Assume I'm going to need a pretty full featured GUI (Windows, Buttons, Listboxs, Textbox’s, Scrollbars, Images, ECT...). Any one who has ever worked with a GUI, designed their own GUI, or even remotely considered the design challenges of creating their own GUI, knows that many GUI objects have similar attributes, properties, methods, events and interfaces. For example, an Image will generally have a width, height, left, and right positions. And these positions can be defined in several ways (relative to screen, parent, pixels vs. percent, ECT...). But so does a Window, a Frame, a button, a Scroll bar, ECT... Another example, the application programmer using the GUI will certainly need some sort of event notification of when a button is pressed. But he might also want the same sort of notification when an image, a Window, or a checkbox is pressed. The point being that almost all GUI objects can be thought of as different combinations of common properties or interfaces. There are two general strategies to take advantage of this situation from the programmer's perspective. 1 -- Every class derives from base classes that contain specific properties. Usually, these objects would be called "Dimensions", "Font", ECT... This approach is nice because it allows for a high level of code re-use with strong logical separations. However, many purveyors of OOP have issues with this method because the "Is a..."/"Has a..." distinction. Specifically, Classes shouldn't derive from "Font" because inheritance is an "Is a..." relationship, when the correct relation ship here is "Has a...". This distinction leads to the second common solution: 2 -- Every class contains several base objects that are each responsible for a specific peace of functionality. This is generally known as the composite pattern. This approach is nice because the "Is a"/"Has a" logical relationship is maintained. The problem I find with this method lies in the implementation details. For example, now that a Textbox is no longer derived from Font, I must write wrapper methods for every piece of Font functionality I would like to expose through textbox; like SetFont(), SetFontHeight(), SetCharSpacing(), ECT... In addition, in the previous class layout, I could have stored a list of all objects that contain dimensions, so that I might move everything to the right by 5 pixels. Now, in order to do the same thing, I will need some other much more complex solution to do a relatively small task. So my solution is a solution of semantics. In order to escape the implementation struggles of the composite pattern, I use the "Is a..." relationship correctly by simply changing the name of "Font" to "ObjectWithFont". Now, a Textbox can derive from ObjectWithFont, ObjectWithDimensions, and ObjectWithFrame. All the code is reused, no cumbersome wrappers need be written, and a Textbox certainly "Is a" ObjectWithFont, an ObjectWithDimensions, and an ObjectWithFrame. Suddenly the distinction between "Is a..."/"Has a..." relationships, and choosing the right one for a particular class design -- appears to be a petty semantic qualm of over-zealous design gurus. Thoughts?

