Linköpings universitet IDA Department of Computer and Information Sciences Prof. Dr. Christoph Kessler EXAM TDDD05 Component-based Software 2010-06-02, 14:00–18:00, U7, U10, U11, U14, U15, R41 Examinator: Christoph Kessler Jour: Christoph Kessler (070-3666687, 013-282406), visiting ca. 15:30, 16:45 Hjälpmedel / Admitted material: Engelsk ordbok / Dictionary from English to your native language General instructions This exam has 9 assignments and 4 pages, including this one. Read all assignments carefully and completely before you begin. Please use a new sheet of paper for each assignment. Number all your sheets. You may answer in either English or Swedish. Write clearly. Unreadable text will be ignored. Be precise in your statements. Unprecise formulations may lead to a reduction of points. Motivate clearly all statements and reasoning. Explain calculations and solution procedures. The assignments are not ordered according to difficulty. The exam is designed for 40 points. You may thus plan about 5 minutes per point. Grading: U, 3, 4, 5. The preliminary threshold for passing (grade 3) is 20 points. International master students and exchange students will receive ECTS grades. ECTS grades will be set according to the LiU guideline for direct translation from Swedish grades: 5=A, 4=B, 3=C, U=FX. 1 1. (1.5 p.) Components and Composition (a) Define the terms black-box composition and grey-box composition, and name an example composition system (no details) for each of these. (1.5p) 2. (6 p.) OO technology and design by contract (a) In the context of design by contract, we considered the concept of syntactic substitutability (Liskov substitutability). Explain which constraints this imposes on the component provider when evolving the interface/component by creating a new subclass of the old interface/component as a substitute that should still work properly with any existing client code. In particular, explain (i) why covariance of method parameter types would be a desirable modification in the new subclass from the provider’s point of view, and (ii) for which of the different kinds of method parameters (input parameters, return values and exceptions) covariance is permitted without breaking existing client code, and for which it is forbidden. (2p) (b) Describe the Syntactic Fragile Base Class Problem and its implications for the compatibility of binary components compiled from OO programs. Give also a simple example that exhibits the problem. Which fundamental property of OO languages causes the problem? Suggest one (technical) method to overcome the problem. (3p) (c) Can the syntactic fragile base class problem also occur for base classes that contain no methods at all (only data fields)? If yes, give a short code example and explain what happens. If not, explain why. (1p) 3. (7.5 p.) Metaprogramming (a) Define the term metaprogram. (0.5p) (b) What is introspection? (0.5p) Give one example (technical term or short description, no code) for how introspection is used in a component system. (0.5p) (c) Given a class DistributedArray (here is an example of one that stores floats) that should be made generic such that it can be parameterized in the element type. class DistributedArray { private: float localElements[MAX_NUMBER_OF_LOCAL_ELEMENTS]; unsigned int nrOfElements; unsigned int toLocal( unsigned int i) {...}; //index transformation public: DistributedArray ( unsigned int globalLength ) {...} //constructor float getElementAt ( unsigned int globalIndex ) { // ... return localElements[toLocal(globalIndex)]; } void setElementAt ( unsigned int globalIndex, float value ) { // ... localElements[toLocal(globalIndex)] = value; } } 2 (i) Use either C++ templates or invasive software composition to provide a generic version (code) of DistributedArray, (ii) show (code) how to instantiate from the generic class a DistributedArray of doubles; (iii) using appropriate pseudocode, explain what is being generated by the instantiation. (If you do not recall the exact syntax, invent your own and explain the meaning of each construct carefully.) (2.5p) (d) What are traits in C++ template metaprogramming? Why can traits be useful in component composition? (2p) (e) Considering the mechanisms for realizing generic data types, how do Java Generics differ from C++ templates? (1p) Not considering the remaining language issues, which mechanism is to be preferred (i) if code size matters? (0.25p) (ii) if execution time matters? (0.25p) 4. (6.5 p.) CORBA (a) How does CORBA achieve programming language transparency for static calls? (Describe the principle and those main parts involved in CORBA static calls that are primarily relevant for enabling language transparency. In particular, what does each of these parts do at a call? and which parts are generated, and from what source?) (3p) (b) Name three main tasks of an object adapter in CORBA. (1.5p) (c) What are the two main tasks performed by the CORBA Naming Service? (1p) (d) What is the purpose of the IIOP (Internet Inter-ORB Protocol)? In particular, for what kind of calls is it used? (1p) 5. (7 p.) Enterprise JavaBeans (EJB) (a) Enterprise JavaBeans (EJB) allows for separation of business logic from some middleware services. Give two examples of such middleware services and describe how Enterprise JavaBeans handles them. (2p) (b) For each Enterprise JavaBean (EJB), the developer must specify which kind of bean it is. What are the 3 different kinds of Enterprise JavaBeans? (1p) (c) Describe the EJB Facade design pattern. Draw a picture. Name and explain each item in your drawing and indicate its main purpose. Remember to state the type of every EJB you use. (2p) (d) Web Services and EJBs share many common features. One can even implement an end point of a Web Service using EJBs. There are, however, principle differences in the way Web Services and EJBs are deployed and discovered. Which of the following statemenets are true in your view? Correct the statements you disagree with. Motivate your answers. 3 i. ”Both Web Services and EJBs allow metalevel description of the services (beans) they provide.” ii. ”Both Web Services and EJBs have a central repository that enables automatic discovery of services (beans) using metalevel descriptions.” (2p) 6. (3.5 p) Aspect-oriented Programming (AOP) (a) Write an Aspect-J program that inserts immediately after each call to a function foo a print statement that prints a log message containing the function’s name to standard output. Explain carefully what the different constructs that you use are (using Aspect-J terminology), and what they do. If you do not remember the exact Aspect-J syntax, invent your own one, and explain what it means. (2.5p) (b) What is the greatest new problem that comes with aspect-oriented programming? (1p) 7. (3 p.) Model-driven architecture (MDA) (a) What is a UML profile, and why are profiles important for model-driven development with MDA? (2p) (b) Give two main arguments how using MDA can increase programmer productivity. (1p) 8. (2 p) Web services (a) What is the purpose of each of the following protocols and specification languages used in web services: - SOAP - WSDL - UDDI - BPEL (alternatively, BPMN)? (2p) 9. (3 p.) Invasive Software Composition (a) What is a hook in invasive software composition? (0.5p) (b) In the COMPOST system, hooks and fragment boxes are strictly typed. What do these types represent, and why is this typing important? (2p) (c) Reuseware, the successor of the COMPOST system, is another system for invasive software composition. What is the main feature that makes Reuseware more general than COMPOST? (0.5p) Lab bonus: The optional Ladok moment for the timely completed optional lab series has already been reported at the time of the exam. If applicable, your exam score will be increased with 4 lab bonus points. Good luck! 4