


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Note: If you collaborated with your classmates or used their notes, please note which classmates you collab- orated with. If you use an external source, besides the text book, lectures, notes provided by the instructor, and your own intellect, please cite that source. Use quote marks if you are quoting material word-for-word from any source (including the text book).
Data Abstraction (Chapter 9 )
(a) What is the oldest abstraction mechanism provided by programming langauges? And what does it encapsulate? Procedures, which encapsulate code. (b) List three features of data abstraction mechanisms provided by lan- gauges. i. āidentifying the interface of the data structureā ii. āproviding information hidingā iii. āallowing the data structure to be used in different ways by differ- ent programsā
(a) What is the difference between an interface and a specification? An interface is the externally visible parts (e.g., operation names, types, parameters) through which a client interacts with a component. There is often explicit language support for defining the interfaces and en- suring that the client and component implementation agree on it (e.g., public methods/fields in Java and declarations in header files in C). The specification is a description of the behavior of a component as visible through its interface. If the implementation does not satisfy the spec- ification, then the client may not work correctly. But there is usually no automatic mechanism to determine if the implementation satisfies the specification. (This is one of the primary goals of unit testing.) (b) In MLās abstype construct only the abstract type name and the names and types of the values/functions declared in the abstype are externally visible. What is the externally visible interface of: exception Empty ; abstype queue = Q of int list with fun mk_Queue () = Q ( nil ) and is_empty ( Q ( l )) = l = nil and add (x , Q ( l )) = Q ( l@ [ x ]) and first ( Q ( nil )) = raise Empty | first ( Q ( x :: l )) = x and rest ( Q ( nil )) = raise Empty | rest ( Q ( x :: l )) = Q ( l ) and length ( Q ( nil )) = 0 | length ( Q ( x :: l )) = 1 + length ( Q ( l )) end ;
e x c e p t i o n Empty type queue val mk Queue = f n : u n i t ā> queue val is empty = f n : queue ā> bool val add = f n : i n t (^) * queue ā> queue val f i r s t = f n : queue ā> i n t val r e s t = f n : queue ā> queue val l e n g t h = f n : queue ā> i n t
Overview of Object-Orientation (Chapter 10 )
(a) List the four steps of Grady Boochās approach to object-oriented design. i. āIdentify the objects at a given level of abstraction.ā ii. āIdentify the semantics (intended behavior) of these objects.ā iii. āIdentify the relationship among the objects.ā iv. āImplement the objects.ā (b) List the four main language concepts for object-oriented programming. i. dynamic lookup ii. abstraction iii. subtyping iv. inheritance
(a) What is dynamic lookup (a.k.a., dynamic dispatch)? It is a mechanism that allows objects to respond in different ways to the same āmessageā based on the dynamic identity of the receiving object. (b) How does dynamic lookup (e.g., a method invocation in Java) differ from an ordinary function call (e.g., in C)? In an ordinary function call, the code that is being jumped to is de- termined by the name of the function (and perhaps overloading based on the type of the functionās parameter) or by an explicit function val- ue/pointer. With dynamic lookup, there is an implicit mechanism that determines the method implementation based on the dynamic identity of the receiving object. (c) What is the key word for declaring a member function with dynamic lookup in C++? virtual
(a) What do object-based abstraction and data abstraction both encapsulate (or as Mitchell says ācombineā)? functions (code) and data
It is possible to mimic many aspects of objects in ML using records and closures. What is it about object-oriented programs cannot be mimicked using records and closures? subtyping and inheritance
(a) What is a design pattern?
āA design pattern is a guideline or approach to solving a kind of prob- lem that occurs in a number of specific forms.ā (b) List two design patterns. The two described in the textbook are Singleton and Facade. In addi- tion, the Visitor design pattern was described in lecture and in lab. (c) How does the organization of a typical object-oriented program dif- fer from an equivalent program with a conventional function-oriented organization? A program with a conventional function-oriented organization, will be divided up into functions to handle different logical operations. Each function may be further subdivided into separate cases for han- dling different types of data. The code related to each data type will be spread across several functions. In contrast, in a typical object- oriented program, the data type is the primary organization criteria and the operation is secondary to that. So the different code related to a single logical operation will be spread across the different classes in the class hierarchy. (d) What design pattern allows a program to use subtyping and dynamic lookup to achieve an organization/effect similar to the type case used on p. 288 in your text book? (The answer to this question is not in the text book.) The Visitor Design Pattern describes a way of arranging objects so that one achieves a operation-oriented organization for code using object- oriented mechanisms (primarily subtyping and dynamic lookup).