Am 29.07.2009 um 15:54 schrieb Damien Cassou:
2009/7/29 Mariano Martinez Peck <marianopeck@gmail.com>:
On Tue, Jul 28, 2009 at 5:39 PM, Igor Stasenko <siguctua@gmail.com> wrote:
I think that all such kind of queries (like isXXXPlatform) should be not included and not used in a well-designed system. If you want some capability - then you should ask directly for it, irrespectively on what platform you are currently running.
I am agree. I really believe in the phrase "tell don't ask". However, I have a couple of things to say:
1) It is not as easy as it seems. If you want to delegate to another object and be polymorphic regarding the platform you must reify a couple of classes (in your slash it is easy because you have the File hierarchy). I mean, you cannot put everything in the Platform class. And this must be done in every place. You must really understand that piece of code to change it. I can do this in my projects, but I don't know about to do it everywhere.
The class OSPlatform is quite small. I would vote for:
- implementing the following methods
OSPlatform>>isMacOSX ^ false OSPlatform>>isWin32 ^ false OSPlatform>>isUnix ^ false
and then
MacOSXPlatform>>isMacOSX ^ true UnixPlatform>>isUnix ^ true Win32Platform>>isWin32 ^ true
- when you want to test the platform, just do:
OSPlatform current isMacOSX
or
OSPlatform current isWin32
What do you think?
When I learned object orientation one of the first things I encountered was: "Procedural code makes decisions, object oriented code delegates." Or, sometimes simply: "Tell, don't ask!". For me this looks like asking... Regards Andreas