1 2 Previous Next 17 Replies Latest reply on Aug 30, 2010 7:47 PM by 843853 Go to original post
      • 15. Re: Need help with Factory Pattern.
        Blocked a post, and locked an account due to spamming.

        • 16. Re: Need help with Factory Pattern.
          One possibilty is to have empty constructors and initialise the properties after the factory has returned the objects.
          Car car = TransportFactory.createCar();
          etc etc
          The problem with this is if you add another property, to say Car it will not get set throughout your code base unless you modify all occurences of the above code.

          This suggests it is better to have
          Car car = TransportFactory.createCar( color, numberofwheels ) 

          because when you add another property, you will need to change the signature of you creation method and a subsequent rebuild will highlight all the places that you need to think about initialising the new property.

          Of course the alternative is to go with suggestion 1 and initialise the propty to a default value in the contructor of the Car class.

          • 17. Re: Need help with Factory Pattern.
            You could use a constructor with varargs for your child clasess. This way you can have classes with the same constructor signature, but of course, you'll still have to write the constructors.

            Little dirty but your domain seem a little messy.
            1 2 Previous Next