Exforsys
+ Reply to Thread
Results 1 to 2 of 2

what pattern or policy to use.

This is a discussion on what pattern or policy to use. within the Software Patterns forums, part of the Testing category; This is the problem, the class diagram is C Impl IC EC SImpl HImpl Where IC and EC are derived ...

  1. #1
    sanjiv Guest

    what pattern or policy to use.

    This is the problem,

    the class diagram is


    C Impl

    IC EC SImpl HImpl

    Where IC and EC are derived from C(Abstract) and SImpl and HImple are
    derived from Impl(Abstract). C keeps a pointer to Impl.

    If I have to invoke a function of SImpl then I can declare a virtual
    function in Impl and do it, straight forward.
    Question is, if I have to write a function which only makes sense for
    SImpl and not for HImpl and this function is to be called from IC.
    Then how should I do it using patterns or policy.
    Any suggestion....
    Thanks



  2. #2
    Ken Loh Guest

    Re: what pattern or policy to use.

    Here's my 2 cents worth:

    class C {
    private Impl impl;
    protected setImpl(Impl impl) {
    this.impl = impl;
    }
    public someMethod() {
    Object ref = impl.anImplMethod();
    ....
    }
    }

    public class IC extends C {
    C(Impl impl) {
    super();
    setImpl(impl);
    }
    public void someMethod(){
    assert impl instanceof SImpl;
    Object ref = ((SImpl) impl).aSImplMethod();
    ....
    }
    }

    Cheers

    sanjrd@yahoo.com (sanjiv) wrote in message news:<8ad413cf.0411021420.7a33d889@posting.google.com>...
    > This is the problem,
    >
    > the class diagram is
    >
    >
    > C Impl
    >
    > IC EC SImpl HImpl
    >
    > Where IC and EC are derived from C(Abstract) and SImpl and HImple are
    > derived from Impl(Abstract). C keeps a pointer to Impl.
    >
    > If I have to invoke a function of SImpl then I can declare a virtual
    > function in Impl and do it, straight forward.
    > Question is, if I have to write a function which only makes sense for
    > SImpl and not for HImpl and this function is to be called from IC.
    > Then how should I do it using patterns or policy.
    > Any suggestion....
    > Thanks




Latest Article

Network Security Risk Assessment and Measurement

Read More...