Don
Posts: 2
Nickname: puffybsd
Registered: Oct, 2003
|
|
Re: The C++ Style Sweet Spot
|
Posted: Oct 14, 2003 1:20 PM
|
|
> > So, how would you refactor JFrame in Java, or > > CWnd in MFC, for example? Or at least, what > > general approach would you take?
Let's face it, CWnd wraps an awful API. Even the much cleaner WTL version, CWindow, has a bunch of gunk. (JFrame is much better, IMHO, but still has gunk).
Where does the gunk come from? The gunk comes from trying to take on too much responsibility at once. These windowing classes are responsible for registering messages, handling timers, resizing themselves, attaining focus, changing style, interacting with peers, tracking their children, repainting, bitblting and self-disposal.
The fix is to strip down the Window class to the bare minimum of what a Window is (rectangle) and let other classes (or libraries) handle the extraneous or unrelated. WindowStylist - in charge of decorating windows, WindowPlanner - handles windows events, WindowGrimReaper - in charge of managing the window life cycle*.
Suddenly the CWnds of the world look a lot simpler. Other classes are shouldering some of the burden. But wait, this might seem ugly because it's kind of procedural.
But there's more to the ugliness than that. Developers entertain mixed metaphors when it comes to windows. On one hand, a window is a rectangle. On the other hand, a window is a metaphor for the Application as a whole.
So developers want to see the simple setTitle(), resize(), close() API that is Window As Rectangle, but also expect the kitchen sink interface that properly reflects Window As Whole Enchilada.
In a way, the WAWE metaphor provides a nice Facade pattern implementation to everything. But it's unsettling when we look for the simplier interface. My answer to refactoring: change the name of the class from JFrame to JVisualKitchenSink and CWnd to CVisualWholeEnchiladaApplication
*(I have a whole version with private delegates for defaults in my mind).
|
|