7
gitpush
6y

Did I screw up or is it ok doing this?

1. Calling another method inside the same factory file
2. Calling a method from another factory file
3. All factory methods are static because they only depend on their passed parameter(s)

Comments
  • 1
    Don't think those are actual factories man. I'd shorten the method names.
  • 1
    My small gripe: get rid of the if else and rethink if your function needs should return something when you do:

    CreateCustomer();
  • 0
    @beegC0de @D--M so it looks like I don't have 100% understanding of factory stuff...
    What am I missing other than what you guys mentioned?
  • 1
    Pretty sure that's not how factories work. It has to work like a literal factory, where you send in X raw material inputs, process them and always spit out a similar output for each particular input. Like a car factory would do. Take in parts and spit out a car.

    If it has side effects, or non exclusive dependencies, it isn't a factory. If it's not dealing with one particular type of processing, with known inputs and outputs, it isn't a factory. You can't build flashlights in a car factory.
  • 0
    @hashedram I understand now, I'll rewrite my code making in hope I get it right this time
  • 1
    @gitpush if you don't *need* factories then don't use them. Really you'll know when you need them. Ex) you have all these specialized versions of a user where there are only slight difference in the way you have to create them, but you don't want to implement the same function over and over to create them with only minor modifications. If you can encapsulate that creation behavior, then that is when you could use a factory.
  • 1
    @beegC0de I see, I'll keep that in mind thanks man 😀
Add Comment