Skip to content

Patterns

August 28, 2010

Proxy pattern – do not use a wrapper class because of additional methods not implemented limitations.Need to take care of the

  • exceptions that can be thrown.
  • equals method
  • Structural patterns: proxy,adapter, composite and decorator.

    In proxy – clients talk to subject not to the implementation (hide the impl) . In decorator clients talk to the implementation class that has added on features. Dynamic proxy uses only interfaces (JavaCompiler allows subclassing and also for improved performance).

    CGLIB Proxy -vs – JDK Proxy….

    Object Adapter: implements target interface and delegates calls to nested objects inside. (Delegation) /OR/ extends the target class and delegates to nested objects.

    Class Adapter: Extends the existing class and implements target interface and call’s the super class methods

    Strategy Pattern
    1. Inheritance is for behavior and NOT for state.

    2. Can use any of the 4 factory methods – ? creational patterns for choosing the right strategy class.

    3. Vtable lookup – if more than 3 concrete strategies otherwise if/else statements used by compiler,

    4. Strategy objects contain some state – if you increase number of objects – then it may cause some issue.

    Adapter
    class adapter – override
    object adapter – does not allow to override methods

    public constructr(final Enumeration en)
    {

    this(new Iterator() { //using the en over here to next() { en.nextElement();}
    // question is: how are we using the final variables in the nested anonymous classes?
    }

    Iterator
    always make sure you know the INTENT of the structure. If the INTENT is known the pattern will be known.
    Otherwise sometimes its dificult to say looking at the structure what kind of pattern was used.

    internal and external iterator.
    some iterator have int – that tell which position to start with – no reset – but can move previous/next
    insert/remove does not impact traversal

    Advertisements
    No comments yet

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: