SlideServe
Menu
Préférences
© SlideServe · v2026

Lorenz: Visitor Beans: An Aspect-Oriented Pattern

love avatar
22 diapositives · 458 Views · May 20, 2012

Lorenz: Visitor Beans: An Aspect-Oriented Pattern. Aspect-oriented pattern: describes a solution to a tangling problem in a particular context. AOP = control of tangling. Demeter/Java controls the following tangling problems structure/behavior, navigation/behavior, behavior/behavior,

Lorenz: Visitor Beans: An Aspect-Oriented Pattern - slide 1
01 / 22Lorenz: Visitor Beans: An Aspect-Oriented Pattern
1 / 17

Télécharger la présentation

Lorenz: Visitor Beans: An Aspect-Oriented Pattern
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Lorenz: Visitor Beans:An Aspect-Oriented Pattern • Aspect-oriented pattern: describes a solution to a tangling problem in a particular context.

  2. AOP = control of tangling • Demeter/Java controls the following tangling problems • structure/behavior, • navigation/behavior, • behavior/behavior, • object construction/structure, • synchronization/behavior, • remote invocation/behavior.

  3. Java Bean: a Java class • Provides: methods and events • Requires: listens to events from other beans • pcs.firePropertyChange("n", old, new)

  4. Java Beans • Software Component Model for Java • Introspection: what methods and events are available. Builder tool can inspect a bean. • Support for customization • Events: for communication between beans

  5. Java Beans • Three most important features • set of properties it exposes • set of methods it allows other beans to call • set of events it fires • event listeners can be associated with event source • when the event source detects something, it will call an appropriate method on the event listener object

  6. Java Beans • Design-time versus run-time. A bean must be capable of running in a • design environment: design information, customization (code can be large: wizard style customization) • run-time environment

  7. Clear separation:design-time and run-time aspects • Design-time interfaces can be supported in a separate class from the run-time interfaces • It is possible to deploy a bean at run-time without needing to download all its design time code

  8. Links to remote state • Java bean runs in same address space as their container • Network access mechanisms available: • Java RMI • Java IDL: CORBA • JDBC: Java data base API

  9. Alternate type views • First release: each bean a single Java object • Future releases: beans that are implemented as a set of cooperating objects. • Type view: represents a view of a bean as a given type • In future releases: different type views of a bean may be implemented by different Java objects.

  10. Events Source Listener

  11. Goal • Enable discovery of the events that a particular class may generate • Enable the discovery of the events a class may observe • Common event registration mechanism for dynamic manipulation of relationship between sources and listeners

  12. Design patternsused with a different meaning • The standard design pattern for EventListener registration (multicast event source): • public void add<ListenerType>(<ListenerType> listener); • public void remove <ListenerType>(<ListenerType> listener); • should be synchronized methods

  13. Java Beans preferred format • public PropertyType get<PropertyName>(); // simple getter method • public void set<PropertyName>(PropertyType var); // simple setter method • public PropertyType get<PropertyName>(int index); // indexed getter method • public void set<PropertyName>(int index, PropertyType var); // setter method • public PropertyType[] get<PropertyName>(); // indexed getter method • public void set<PropertyName>(PropertyType[] var); // indexed setter method

  14. Defining events and listeners public class ContainerEventObject extends EventObject {…} public interface ContainerListener extends EventListener { void handleContainerEvent(ContainerEventObject ceo); }

  15. Listeners for Container bean private Vector containerListeners = new Vector(); public synchronized void addContainerListener(ContainerListener l) { containerListeners.addElement(l); } public synchronized void removeContainerListener(ContainerListener l){ containerListeners.removeElement(l); }

  16. Broadcasting event public void broadcastContainerEvent() { Vector l; ContainerEventObject ceo = new ContainerEventObject(this); synchronized(this) { l = (Vector)containerListeners.clone(); } for (int i = 0; i < l.size(); i++) { ContainerListener cl = (ContainerListener)l.elementAt(i); cl.handleContainerEvent(ceo); } }

  17. Visitor Bean • Accept methods: use reflection to define a traversal visitor! • Visit methods: Instead of sending a visitor to visit an element, the element is fired to the visitor as part of an event.

  18. In class Visitor public void visit_dispatch(Object o){ Class[] formal = new Class[1]; formal[0] = o.getClass(); try { Method m = getClass().getMethod(“visit”, formal); Object[] actual = new Object[1]; actual[0] = o; m.invoke(this, actual); } catch (Exception e) { } }

  19. Visit events • Visitors report their actions via events • event objects may contain visited objects • visitors may register as event listeners to other visitors • Events are typed: registration is typesafe

  20. VisitEvent Package visitor.beans.event; import java.util.EventObject; public class VisitEvent extends EventObject { protected VisitEvent(Object source, int type, Object visited, Object[] data) { super(source); fieldType = type; fieldVisited = visited; fieldData = data; } private transient int fieldType = 0; … }

  21. Visitor kinds • Traversal visitors: • manipulate the visitee part and pass data without looking at it • Computational visitors: • pass the visitee untouched and manipulate only the data

  22. Adaptive Bean: visitor style strategy in Local adaptive beans out nodes + edges enter + exit terminate node + edge Traversal status events (contain objects traversed)