Difference between revisions of "Subclassing Application Class"
From MorphOS Library
(Contents++.) |
(Crosslinking++;) |
||
(34 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
''Grzegorz Kraszewski'' | ''Grzegorz Kraszewski'' | ||
+ | ---- | ||
+ | <small>This article in other languages: [[Klasy pochodne od klasy "Application"|Polish]]</small> | ||
− | + | Every MUI application is (or at least should be) an [[Event Driven Programming, Notifications|event driven]] one. This means the application provides a set of actions, which may be triggered with user activity (like using the mouse and keyboard). The straightforward way of implementing this set of actions is to implement it as a set of methods added to some MUI object. For simple programs, the best candidate for adding such methods is the master ''Application'' object. More complex programs (for example ones using a multi-document interface) may add actions to other classes, for example the ''Window'' class. | |
− | Every MUI application is (or at least should be) an event driven one. | ||
Why methods? Implementing actions as methods has many advantages: | Why methods? Implementing actions as methods has many advantages: | ||
− | * Methods may be used directly as notification actions. It saves a programmer from using hook tricks or cluttering the main loop with | + | * Methods may be used directly as [[Event Driven Programming, Notifications#Notifications in MUI|notification]] actions. It saves a programmer from using hook tricks or cluttering the main loop with lots of ''ReturnID'' values. |
* Methods may be coupled directly with scripting language interface (formerly known as ARexx interface) commands. | * Methods may be coupled directly with scripting language interface (formerly known as ARexx interface) commands. | ||
− | * Methods used in notifications are executed immediately in response | + | * Methods used in notifications are executed immediately in response to user actions. No delay is introduced by the main loop (especially if it is not empty). |
− | * A notification triggering attribute value may be passed directly to method | + | * A notification triggering attribute value may be [[Event Driven Programming, Notifications#Reusing Triggering Value|passed directly]] to a method as its parameter. |
− | * Using methods improves code modularity. | + | * Using methods improves code modularity and object encapsulation. Functionality meant to be handled in the scope of an object is handled in its method, without the code spreading across the project. |
− | + | In a well designed MUI program, all program actions and functionality are implemented as methods and the program internal state is stored as a set of attributes and internal application instance data fields. An example of such a program is discussed throughly in the [[MUI Subclassing Tutorial: SciMark2 Port]] article. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[ | ||
− | |||
− |
Latest revision as of 13:49, 27 January 2011
Grzegorz Kraszewski
This article in other languages: Polish
Every MUI application is (or at least should be) an event driven one. This means the application provides a set of actions, which may be triggered with user activity (like using the mouse and keyboard). The straightforward way of implementing this set of actions is to implement it as a set of methods added to some MUI object. For simple programs, the best candidate for adding such methods is the master Application object. More complex programs (for example ones using a multi-document interface) may add actions to other classes, for example the Window class.
Why methods? Implementing actions as methods has many advantages:
- Methods may be used directly as notification actions. It saves a programmer from using hook tricks or cluttering the main loop with lots of ReturnID values.
- Methods may be coupled directly with scripting language interface (formerly known as ARexx interface) commands.
- Methods used in notifications are executed immediately in response to user actions. No delay is introduced by the main loop (especially if it is not empty).
- A notification triggering attribute value may be passed directly to a method as its parameter.
- Using methods improves code modularity and object encapsulation. Functionality meant to be handled in the scope of an object is handled in its method, without the code spreading across the project.
In a well designed MUI program, all program actions and functionality are implemented as methods and the program internal state is stored as a set of attributes and internal application instance data fields. An example of such a program is discussed throughly in the MUI Subclassing Tutorial: SciMark2 Port article.