2 Replies Latest reply: Dec 1, 2009 7:47 AM by 800387 RSS

    Java Facade question

    843853
      I am creating a facade class for an application. My question concerns whether or not facade classes are supposed to contain variables and data themselves. For example, can I define some data underneath where I have the DefineMeeting object declared? Essentially, are facade classes supposed to declare varialbes and manipulate them, or simply let other classes accomplish those tasks?

      public class EmployeeManagement implements Employee{

           DefineMeeting meeting = new DefineMeeting();
           //int employeeID;
      //String employeeNamel

           public void clearAttendees()
           {
                meeting.clearAttendees();
           }
           
           public void defineNewMeeting(String meetingday, String meetingtimeofday, String nameofmeeting, String meetingdescription)
           {
                meeting.createMeeting(meetingday, meetingtimeofday, nameofmeeting);
                meeting.addDescription(meetingdescription);
           }
      }
        • 1. Re: Java Facade question
          dcminter
          Essentially, are facade classes supposed to declare varialbes and manipulate them, or simply let other classes accomplish those tasks?
          It depends what you're using your facade to accomplish.

          Please use the code tags when posting code in future.
          • 2. Re: Java Facade question
            800387
            It's not explicitly part of the design pattern, but normally a facade fronts a service. Services are stateless, so I would be surprised to see a facade that did have state. That having been said, you could mingle some controller concepts with a facade and have state (for example, a facade that accepts a series of web page responses, ala a wizard, that then forwards an entire coarse-grained service request).

            As DCMinter indicated, it depends on what you are trying to do. Don't think in terms of patterns. Think in terms of goals. Don't create new tiers in your architecture until they are merited. (Sadly, the Deepak Alur's J2EE patterns book has encouraged far too many projects to adopt an onion-like structure where most of the tiers are coded only for consistency sake rather than to meet any actual requirement. No offense to Mr. Alur.).

            - Saish