We can compare smalltalk interfaces to classes that use


Protocol Conformance

We can compare Smalltalk interfaces to classes that use protocols, which are lists of operation names (selectors). When a selector allows parameters, as in at: put: , the selector name includes the colons but not the spaces. More speci?cally, if dict is an updatable collection object, such as a dictionary, then we could send dict a message by writing dict at:‘cross' put:‘angry'. (This makes our dictionary de?nition of "cross" the single word "angry.") The protocol for updatable collections will there- fore contain the seven-character selector name at:put: . Here are some example protocols:

stack : {isEmpty, push:, pop }
queue : {isEmpty, insert:, remove }
priority queue : {isEmpty, insert:, remove }
dequeue : {isEmpty, insert:,insertFront:, remove, removeLast }
simple collection : {isEmpty }

Brie?y, a stack can be sent the message isEmpty, returning true if empty, false oth- erwise; push: requires an argument (the object to be pushed onto the stack), pop removes the top element from the stack and returns it. Queues work similarly, ex- cept they are ?rst-in, ?rst-out instead of ?rst-in, last-out. Priority queues are ?rst-in, minimum-out and dequeues are doubly ended queues with the possibility of adding and removing from either end. The simple collection class just collects methods that are common to all the other classes. We say that the protocol for A conforms to the protocol for B if the set of A selector names contains the set of B selector names.

(a) Draw a diagram of these classes, ordered by protocol conformance. You should end up with a graph that looks like William Cook's drawing shown in Figure 11.6.

(b) Describe brie?y, in words, a way of implementing each class so that you make B asubclass of A only if the protocol for B conforms to the protocol set for A.

(c) For some classes A and B that are unrelated in the graph, describe a strategy for implementing A as a subclass of B in a way that keeps them unrelated.

(d) Describe implementation strategies for two classes A and B (from the preceding set of classes) so that B is a subclass of A, but A conforms to B, not the other way around.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: We can compare smalltalk interfaces to classes that use
Reference No:- TGS01269957

Expected delivery within 24 Hours