Target-Action

Target-Action

The term Target-Action design paradigm refers to a kind of software architecture, where a computer program is divided up into objects which dynamically establish relationships by telling each other which object they should target and what action or message to send to that target when an event occurs. This is especially useful when implementing graphical user interfaces, which are by nature event-driven.

Advantages

The target-action approach to event-driven systems allows for a much greater deal of dynamism when compared to other, more static approaches, such as by subclassing. That is because subclassing is a relatively stiff way of programming - the programmer has to lay out the internal interconnection logic of a program at design time and this cannot be changed later (unless the program is stopped, reengineered and built again). On the other hand, target-action based programming can change these completely at run-time, thus allowing the program to create new inter-relationships and completely novel behavior all by itself.

A prime example of this approach is the OpenStep API, which partly thanks to being based on the dynamic Objective-C language, has much of its graphical user interface implemented by using the target-action paradigm. Consider the following example (written in the Objective-C language):

[button setTarget: self] ; [button setAction: @selector(doSomething)] ;

Now when the button identified by the button variable is pressed, the runtime system will try to send a message named doSomething to the object in which this code has been invoked. It is also very well possible to determine the message to be sent at run-time:

[button setTarget: self] ; [button setAction: NSSelectorFromString( [textField stringValue] )] ;

Here the message which is to be sent is determined by consulting a text field's string value (the string of text which the user typed into a text field). This string is afterwards converted into a message (using the NSSelectorFromString function) and passed to the button as its action. This is possible because, under Objective-C, methods are represented by a selector, a simple string describing the method to be called. When a message is sent, the selector is sent into the ObjC runtime, matched against a list of available methods, and the method's implementation is called. The implementation of the method is looked up at runtime, not compile time.

Disadvantages

Because of the extreme dynamism and freedom of behavior given to programs designed with the target-action paradigm in mind, it can happen that the program designer incorrectly implements a part of the inter-connection logic and this can lead to sometimes difficult to trace bugs. This is due to the lack of compile-time control provided by the compiler which cannot see the inter-connections. Thus inter-connection consistency control is left entirely up to the programmer.

The result of an incorrectly connected target-action binding can differ based on how the particular system in which the program is implemented regards this:
* it can ignore the condition and perform nothing (such as in the button example above - if the target of a button doesn't respond to its action message, pushing the button simply does nothing)
* it can consider such a state to be a bug, in which case it will most likely cause the program to crash or invoke a run-time exception

See also

* The OpenStep API
** OPENSTEP - an operating system by NeXT Software Inc. (now Apple Computer Inc.) largely based on the OpenStep API
** GNUstep - a free implementation of the OpenStep API
** Cocoa - an OpenStep derived API used on Mac OS X
* Objective-C

External links

* [http://www.gnustep.org The GNUstep project home page]

* [http://developer.apple.com/cocoa The Apple Cocoa API documentation page]


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Target Field — Location 1 Twins Way (3rd Ave. N, between 5th St. N and 7th St. N) Minneapolis, Minnesota …   Wikipedia

  • Target Earth — Éditeur DreamWorks Développeur NCS Masaya Date de sortie 16 mars 1990 (USA) Genre action Mode de jeu Un joueur …   Wikipédia en Français

  • TARGET — tar·get n: the object to be affected or achieved by an action or development; specif: a company that is the object of a takeover Merriam Webster’s Dictionary of Law. Merriam Webster. 1996. target …   Law dictionary

  • target — tar·get n: the object to be affected or achieved by an action or development; specif: a company that is the object of a takeover Merriam Webster’s Dictionary of Law. Merriam Webster. 1996. target …   Law dictionary

  • target cell — n a cell that is acted on selectively by a specific agent (as a virus, drug, or hormone) <the receptor that HIV binds to in entering its target cells (Michael Balter)> * * * 1. a cell that is the focus of attack by antibodies, cytotoxic T… …   Medical dictionary

  • Action for Children — Formation 1869 Type NGO Purpose/focus Children/young people s welfare Location …   Wikipedia

  • Target fixation — is a process by which the brain is focused so intently on an observed object that awareness of other obstacles or hazards can diminish. Also, in an avoidance scenario, the observer can become so fixated on the target that they will forget to take …   Wikipedia

  • Target Acquisition Minefield Detection System — (ASTAMIDS) is the latest weapon in the fight against improvised explosive devices (IED). It will provide a Unit of Action (UA) asset that can be used in Tactical Operations in day or night to detect and locate surface obstacles and recently… …   Wikipedia

  • Action shooting — is a term that encompasses target shooting events where the shooter s score is based on both the accuracy and elapsed time. Disciplines covered by the term include: *United States Practical Shooting Association *International Practical Shooting… …   Wikipedia

  • Action for Children's Television — (ACT) was founded by Peggy Charren in Newton, Massachusetts in 1968 as a grassroots organization dedicated to improving the quality of television programming offered to children. Although concerned about commercial abuses targeted to children,… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”