Re: Advantages of object-oriented programming
- From: "topmind" <topmind@xxxxxxxxxxxxxxxx>
- Date: 23 Oct 2006 10:03:06 -0700
Mike Austin wrote:
Just like clockwork. But anyway, what about we stray away from oop for a
second and get your thoughts on multiple-dispatch? An example in Dylan:
define method handle-event(object,
event :: <mouse-down>,
button == #left-button)
format-out("Left mouse button pressed\n");
end;
No need whatsoever for switch statements. Need to handle a new event? Write a
new method. Override a method but call the original? Call next-method().
I really wish that Dylan had succeeded. It's a beautiful language.
In my opinion, an event manager should be treated more like a database
with a schema something like:
table: Event_Handlers
----------------
object_id // Reference to widgets, such as specific buttons
event_id // Example: "on_click", "mouse_down", etc.
event_priority // optional
event_routine // actual code or a reference
If you have thousands of these, managing them in a database would be
much much easier in my opinion because you can query and report on them
in all kinds of ways.
Now, one may properly argue that a database might be too slow for GUI
usage. I tend to disagree and point out that Visual FoxPro uses roughly
this approach and (now) has pretty good performance (it puts an OO
wrapper around it, ironically). Perhaps in 1995 it was a bit sluggish,
but Moores Law has been nice to database solutions.
Building large, navigational RAM structures is so 80's. DOM is actually
a database of sorts, just not a relational one.
It is also true that one cannot currently "compile" a database for
performance or compile-time type-checking. It may be possible to
generate code to be compiled using this technique. However, one may
lose dynamic debugging ability. I am not a fan of strong-typing anyhow.
But that is a debate orthogonal to OO more or less, because there are
dynamic OOP languages like Smalltalk.
Another advantage of a database-centric solution is that it is more
language-neutral. True, the actual event code probably has to be in a
specific language, but the framework for matching events to event code
could be indepedent of app language. Having a different GUI engine for
Java and say Python is not very logical.
Mike
-T-
.
- Follow-Ups:
- Re: Advantages of object-oriented programming
- From: Dmitry A. Kazakov
- Re: Advantages of object-oriented programming
- References:
- Re: Advantages of object-oriented programming
- From: topmind
- Re: Advantages of object-oriented programming
- From: Mike Austin
- Re: Advantages of object-oriented programming
- Prev by Date: Re: Which pattern for Settings/Preferences/Options scenario?
- Next by Date: Re: Decorator Pattern
- Previous by thread: Re: Advantages of object-oriented programming
- Next by thread: Re: Advantages of object-oriented programming
- Index(es):
Relevant Pages
|