Unformatted text preview:

White-box vs. black-box frameworksCommand patternConduitsNetwork Protocol HandlersSending Messages with ConduitsAdapter PatternSlide 7Features of ConduitsMultiplexorHandling ProtocolsState PatternDelegation in DetailPowerPoint PresentationSlide 14Making Conduits More ReusableCommandCommand in ConduitsVisitorVisitor TradeoffsVisitor in ConduitsImplementing VisitorSlide 22Some PrinciplesSlide 24Adding Connections to a MultiplexorSummary of Patterns in Conduits+Using Patterns in DocumentationSummary01/14/19 White-box vs. black-box frameworksWhite-boxMust understand internalsReuse mostly by inheritanceBlack-boxMust understand interfacesReuse mostly by polymorphism and composition of library classesWhite-box is easier to design, harder to reuse01/14/19 Command patternRepresent a command as an object so you can decouple choosing a command from executing it. Now you can pass it over a network, save it in a menu, undo it, or log it.Blocks and selectors (with perform:) are both light-weight, language-specific implementations of the Command pattern.01/14/19 ConduitsTCP/IP for Choices - Johnny Zweig• white boxATM signaling protocol - ASCOM (Robert Engel, Hermann Hueni)• black boxIssues:• using design patterns• how frameworks become more black box01/14/19 Network Protocol HandlersProtocol stacks - layers of protocol handlers.Messages flow up and down stacks.Stacks should be plug compatible.Should be able to make new stack easily.Each box is a conduit that passes messages up or down the protocol stack.TCPIPEthernetHTTP01/14/19 Sending Messages with ConduitsTCPConduitIPConduitEthernetConduitHTTPConduitSendFromTop(Message *) sends a message down the stack.SendFromBottom(Message *) sends a message up the stack.Who calls SendFromBottom on the EthernetConduit?01/14/19 Adapter PatternIntent: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.An ad apter object will make the adaptee act like it has the target interface.01/14/19 Adapter PatternTargetrequest()ClientAdapterrequest()Adaptee01/14/19 Features of ConduitsTCPConduitARPConduitEthernetConduitUDPConduitIPConduit#1 #2#3#4Multiplexing and demultiplexing BidirectionalOne-ended vs. two-endedTCP ports01/14/19 MultiplexorMux is a kind of composite.ConduitsendFromTopsendFromBottomMuxEthernetConduit01/14/19 Handling ProtocolsState dependent behaviorTCPConduit has many states: open, listening, connected, closing.Legal operations depend on its state.State pattern: split state into separate objectdelegate operations that depend on state to the state object01/14/19 State PatternTCPConduitTCPStateTCPOpenStateTCPClosedStateTCPListeningStatecurrent state01/14/19 Delegation in DetailTCPState has subclasses TCPOpenState, TCPClosedState, TCPListeningState, etc.TCPConduit has a current state that is a subclass of TCPState.TCPConduit delegates operations like send and open to its current state. Many operations change current state of the TCPConduit.Each kind of state has different "send" and "open" methods.TCPConduit has to pass pointer to itself along to current state.01/14/19 TCPState class {public:virtual open( Conduit*);virtual close( Conduit*);virtual send( Conduit*, Message *);...}TCPConduit:: open() {return current_state->open( this );}01/14/19 ConduitsendFromTopsendFromBottomcurrentstateEthernetConduitMuxProtocolStateTCPOpenStateTCPClosedStateTCPListeningStateProtocol01/14/19 Making Conduits More ReusableIdeally, a framework lets you build applications from existing classes, and does not force you to make new subclasses.Reasons to make subclasses of Conduit:• to specify the class of Messages to create• to tell Mux how to dispatch Messages• to add operations to Protocol01/14/19 CommandIntent:Represent the invocation of an operation by an object. This lets you pass the "command" around until you can find which object can handle it, you can undo it, you can put it on a queue and wait for awhile before you handle it, and so on.Command is called "Messenger". It carries the Message.Multiplexors only pass the Messenger on.Protocols use the Messenger to change state.01/14/19 Command in ConduitsChangeSendFromTop(Message *) => SendFromTop(Messenger *)SendFromBottom(Message *) => SendFromBottom(Messenger *)Eliminate all other functions.Messenger passes from conduit to conduit, performing action at Protocols.01/14/19 VisitorProblem:Not all commands should traverse the Conduit graph the same way.In particular, some need to change the graph (add a new Conduit), some need to broadcast.This leads to poliferation of traversal operations in Conduits.Intent:Instead of adding a new operation to a class hierarchy (i.e. Conduit) by adding it to each of (or one of) its subclasses, represent the operation by a separate object.01/14/19 Visitor TradeoffsVisitor works best when it is frequent to create a new operation, but it is rare to create a new class to be operated on.If the only reason to derive a new Conduit class is to add an operation, then using Visitor will mean that it is rare to create a new Conduit class.01/14/19 Visitor in ConduitsChangeSendFromTop(Messager *) => SendFromTop(Visitor *)SendFromBottom(Messager *) => SendFromBottom(Visitor *)Make two kinds of Visitors: UpVisitors and DownVisitors.Then replace SendFromTop and SendFromBottom with one Accept function.01/14/19 Implementing VisitorMultiplexor::Accept(Visitor *aVisitor) {aVisitor->handleMultiplexor( this );}Protocol::Accept(Visitor *aVisitor) {aVisitor->handleProtocol( this );}Visitors cantransport messages (like SendFromTop and SendFromBottom)perform command (like Open and Close)01/14/19 UpVisitor::handleMultiplexor(Multiplexor *conduit) {conduit->parts[partNum()]->Accept(this);}UpVisitor::handleProtocol(Protocol *conduit) {if (message->action(conduit))conduit->upConduit()->Accept(this);}01/14/19 Some PrinciplesConduit and Visitor are coupled.State and Messager are coupled.Messager performs operations on State, but Visitor doesn't.Visitors:MsgTransporter - carries a Messager to a ProtocolInstaller - gets forwarded until it reaches a MuxDisconnector - gets forwarded until it reaches a Mux01/14/19 Mux ProtocolConduitMsgTransporterStateMessagerVisitorcurrent stateVisitor knows how to traverse Conduits.Message is an event that is invoked on State.01/14/19 Adding Connections to a MultiplexorAdaptorMuxProtocolProtocol


View Full Document

UIUC CS 598 - White-box vs. black-box frameworks

Download White-box vs. black-box frameworks
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view White-box vs. black-box frameworks and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view White-box vs. black-box frameworks 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?