Computer Science 313 – Advanced Programming Topics
Why Do We Use Proxy Pattern? Discussed word proxy in Friday's lecture When and why would we ever use a proxy?
Real-World Uses of Proxy
Why We Use Proxy Add level of indirection before real subject Continue actions, but protect subject from harm Create plausible deniability – "But it wasn't me!" Get tasks done, but eliminate need to be local Improve performance by using saved results Same design needs met using Proxy Pattern In all cases, proxy appears identical to real subject Proxy acts first then lets subject do the real work Real subject stays hidden – client does not know
Proxy versus… Adapter Proxy PatternAdapter Pattern
Proxy versus… Adapter Proxy PatternAdapter Pattern Client thinks it does work Uses interface client needs Subject does all work Interface identical to the real subjects Does not change each calls' parameters & return value Cannot access real subject Client thinks it does work Uses interface client needs Adaptee(s) does all work Interface differs with that of adaptee(s) Modifies, adds or removes parameters & return value Can access real subject
Proxy versus… Composite Proxy PatternComposite Pattern
Proxy versus… Composite Proxy PatternComposite Pattern Structural pattern Common interface defined One of GoF's patterns Only one subject used Proxy acts as a gatekeeper Structural pattern Common interface defined One of GoF's patterns Many leaves can be used Composite collects leaves
Proxy versus… Decorator Proxy PatternDecorator Pattern
Proxy versus… Decorator Proxy PatternDecorator Pattern Client thinks it has subject Hides subject from others Proxy can intercept call One proxy per pattern Does not add or modify basic functionality Client thinks has concept Hides concept from others Decorator can intercept call Many decorators per pattern Adds or modifies concept's basic functionality
Proxy versus… Observer Proxy PatternObserver Pattern
Proxy versus… Observer Proxy PatternObserver Pattern
For Next Class Last lab due Friday at end of lab time Start now == more committing acts against man & beast Finish reading on our last design pattern Lots of interesting code on Wednesday Will be presenting many cool & useful hacks Follow the white rabbit – going through the looking glass -----censored 'till tenure-----