Results 1 to 7 of 7

Thread: facade pattern

  1. #1
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default facade pattern

    Hi,

    I've red about the facade pattern, but i have a question: the facade is like a controller object who has a couple of methods who invoke methods from other objects. But i have a kind of controller object who has a couple of getmethods to the objects. Is this a good design too?


    Hannes

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    Your question is not very clear.
    Can you post sore code or more info?

    Have you reconsidered why are you using it at all?
    What is it that you need to hide and simplify in you code?

  3. #3
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    well, i've one object 'Application' who owns the frame, storager, and a couple of other objects. I want to make the Appliction a kind of facade object like in the facade pattern. Some objects hold a reference to Application. Application has a couple of get methods who return the object e.g. the method getFrame( )
    returns the Application's JFrame for example. Is this good design or not?

    Hannes

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Well, that's not really a facade.
    A facade hides complexity by providing a simplified interface to a user.
    Have a look at wiki, it has a couple of reasonable examples.

  5. #5
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    But if you implement in your code, the facade object becomes very big then, and you may have a lot of double code, for example: If you want to get a couple af arrays from an object who holds the array, then you have something like this:

    Java Code:
    class ArrayHolder{
    
    private int[] data;
    
          public ArrayHolder( )
          {
              data=new int[]{1,2,3,4,5,6,7,8,9};
          }
    
          public int[] getData( )
          {
              return data;
          }
    
    }
    
    
    public class Test( )
    {
          private Facade facade;
          public Test( Facade facade)
          {
                  this.facade=facade;
                  int[] data=facade.getData( );
          }
    }
    
    public class Facade
    {
          private ArrayHolder holder;
          private Test test;
          public Facade( )
          {
               holder=new ArrayHolder( );
               test=new Test( this );
          }
    
          public int[] getData( )
          {
                 return holder.getData( );
          }
    
    }

    In the holder you have a method getData and in the Facade you get a method getData. This is like double code,or not?

    Hannes
    Last edited by hannes; 02-09-2010 at 07:27 PM.

  6. #6
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    Can someone answer my question above, please?

    Hannes

  7. #7
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    Hannes you got the point - and that is most important.

    Don't waste your time thinking is that double code
    because example is trivial.

    In real example you would have many classes that enclose some big functionality,
    and you would have to just call few of their methods in right order and put all that in facade's method.
    So on real example code duplication is not a real concern.

Similar Threads

  1. MVC Pattern
    By bubbless in forum New To Java
    Replies: 12
    Last Post: 03-14-2009, 10:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •