• Aucun résultat trouvé

Representing Your Runtime System

Dans le document Object-Oriented (Page 78-82)

The T&M Object Metamodel

FIGURE 2.14 Modeling an

2.7.5 Representing Your Runtime System

Though software developers are normally happy when they don’t have to know the details behind the implementation of a language, there are situations where you have

Information about interfaces to implement dynamic operation calls

to deal with the implementation. For this purpose, an MOP can present a well-defined interface, allowing you to redirect the control flow within the runtime system. This is of interest, particularly in two places:

1. where you store instance variables, and 2. where you call operations.

To disclose the storage algorithm of instance variables, you need two additional operations, that is, one to read an instance variable and another to set an instance variable.

For example, Smalltalk uses the method instVarAt: i to return the value of the ith instance variable. The method instVarAt: i put: value assigns value to the ith instance variable. These two methods are called every time an instance variable is accessed. By overloading these methods, the standard storage algo-rithm can be replaced by your own algoalgo-rithm for all classes or part of the class tree.

Overloading the standard storage algorithm may be useful for efficiency reasons, or to store objects externally.

For objects with many instance variables that are seldom used, it may prove more efficient, in terms of required storage space, to create entries for each of these instance variables in a hash table instead of storing them in a consecutive memory block.

When the state of an object is to be updated immediately to reflect each change to a database, you also need to manipulate the storage mechanism. You can use the mechanisms to represent your application model (see Section 2.7.4) only to implement explicit operation calls to save entire objects.

You can use a metaoperation, to which each operation call is directed, to access the operation call mechanism. This metaoperation can run arbitrary actions either before or after the actual execution. Redirecting operations is useful for the following application domains:

Distributed applications: In this case, the above mechanism lets you redirect operation calls for an object to another computer. To redirect operation calls, you pack the name and arguments of the operation before it is called (also called marshalling) and send the package to the server, where the actual operation runs. The result is then returned to the client, where it is unpacked and forwarded to the caller. The static CORBA (common object request broker architecture) interface is normally implemented in this way.

Persistent objects: In a manner similar to the mechanism used for distributed objects, when an operation is called for an object not residing in the main memory, the call is caught. Based on the object reference, the referenced object is then loaded from a database, before the actual operation call of the freshly instantiated object is executed. In CORBA, this would correspond to the

“incarnation” of an object by an object adapter.

Additional handling of operation calls: There is a large number of algorithms you may want to apply on an operation call before or after it is executed. Good examples are the logging or auditing of operation calls. Another more sophisticated algorithm is used to check the authenticity of the caller and to guarantee to a certain extent that the client really is authorized to call that operation. This is relevant for virtually all software systems.

Manipulating the storage of instance variables

Manipulating operation calls (redirecting operations)

There are different implementation techniques to catch an operation call and have it handled by a metaobject before or after it is executed on the actual target object.

The most common technique hides the target object from the client by using an inter-mediate proxy object. The proxy object catches the operation call and redirects it to the metaobject in charge. In simple cases, it can assume the metahandling itself, as in the example relating to security proxies described in Erich Gamma et al. (Chapter 4) or Frank Buschmann et al. (Section 3.4).

Another implementation technique modifies the virtual machine of a language so that it can work with enhanced object references. The enhancement is the so-called pointer swizzling, where a call is forwarded to a corresponding metaobject. For example, the object-oriented database ObjectStore uses this technique; although it does not for-ward calls to a generically accessible metaobject. Instead, it merely uses a restore mech-anism to wake up the called object in the database.

2 . 8 R E F E R E N C E S

This chapter on the T&M object metamodel has been kept quite concise. For readers who want to delve deeper into the material, we have assembled an annotated list of references that contains both practical and theoretical work.

R. J. Bird and P. Wadler: Introduction to Functional Programming. New York: Prentice Hall, 1988.

A seminal textbook on functional programming.

F. Buschmann, R. Meunier, H. Rohnert, P. Sommerlad, M. Stal: Pattern-Oriented Software Architecture—A System of Patterns. Chichester, New York: Wiley & Sons Ltd, 1996.

A well-received pattern collection book.

L. Cardelli, P. Wegner: “On Understanding Types, Data Abstraction, and Polymorphism”.

Computing Surveys, Vol. 17, No. 4, Dec. 1985.

Seminal work on type systems.

J. Coplien: Advanced C: Programming Styles and Idioms. Reading, Mass.: Addison-Wesley, 1992.

Coplien introduces, among others, the body/handle pattern.

W. Cunningham: “The CHECKS Pattern Language of Information Integrity.” In J. O. Coplien and D. C. Schmidt (eds.): Pattern Languages of Program Design. Reading, Mass.: Addison-Wesley, 1995. Chapter 3, pp. 145–156.

This is an interesting work on (domain) values in object-oriented languages.

E. Gamma, R. Helm, R. Johnson, J. Vlissides: Design Patterns. Reading, Mass.: Addison-Wesley, 1995.

The present chapter refers to patterns from this book.

A. Goldberg, D. Robson: Smalltalk-80: The Language. Reading, Mass.: Addison-Wesley, 1989.

This is a classic among programming language textbooks.

C. A. R. Hoare: “Notes on Data Structuring.” In O.-J. Dahl, E. W. Dijkstra, C. A. R. Hoare:

Structured Programming. London: Academic Press, 1972.

This is a theoretical classic on the concept of type and data types.

R. E. Johnson, V. F. Russo: Reusing Object-Oriented Designs, Department of Computer Science, University of Illinois at Urbana-Champaign, 1991.

This work offers more on abstract classes.

G. Kiczales, J. des Riverieres, D. G. Bobrow: The Art of the Metaobject Protocol. Cambridge, Mass:

MIT Press, 1992.

This work offers more on metaobject protocols.

B. Liskov: “Data Abstraction and Hierarchy.” OOPSLA 1987 Addendum to the Proceedings, ACM SIGPLAN Notices, Vol. 23, No. 5, May 1988, pp. 17–34.

B. Liskov, J. W. Wing: Family Values: A Behavioral Notion of Subtyping. Technical Report, Carnegie Mellon University, CMU-CS-93–187, 1993.

These fundamental theoretical works treat abstract data types and the concept of type.

D. C. Luckham, J. Vera, S. Meldal: Three Concepts of System Architecture. Technical Report CSL-TR-95–674. Stanford, Calif.: Stanford University, 1995.

This work offers more on interfaces.

B. J. MacLennan: “Values and Objects in Programming Languages.” ACM SIGPLAN Notices, Vol. 17, No. 12, Dec. 1982.

This classic article distinguishes values and objects in programming languages.

P. Maes, B. Nardi (eds.): Meta-Level Architectures and Reflection. The Netherlands, Amsterdam:

North-Holland Publishers, 1988.

This book offers more on the metaobject protocol.

B. Meyer: Object-Oriented Software Construction. Second Edition. New York, London: Prentice-Hall, 1997.

This fundamental book covers the concepts and mechanisms of object-oriented programming and programming languages. The explanation of the contract model is particularly important.

D. L. Parnas: “On the Criteria to Be Used in Decomposing Systems into Modules.”

Communication of the ACM, Vol. 5, No. 12, December 1972, pp. 1053–1058.

This classical software engineering paper introduces important principles of modularization and information hiding.

T. Reenskaug, P. Wold, O. A. Lehne: Working with Objects. Greenwich: Manning, 1996.

This book presents interesting aspects of object-oriented design, especially regarding role-modeling.

R. W. Sebesta: Concepts of Programming Languages. Reading, Mass.: Addison-Wesley, 1998.

This is a good practice-oriented textbook about the concepts and constructs of programming languages; it presents design alternatives as examples.

P. Wegner: “Concepts and Paradigms of Object-Oriented Programming.” OOPS Messenger, Vol. 1, No. 1, August 1990, pp. 8–87.

This conceptual article contains the fundamental definition of the term “object-oriented.”

C. Zimmermann (ed.): Advances in Object-Oriented Metalevel Architectures and Reflection. Boca Raton, Florida.: CRC Press, 1996.

Another interesting paper on metaobject protocols.

57

Guiding Metaphors and

Dans le document Object-Oriented (Page 78-82)