Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are (and the difference between) factories, service and util classes? Are there any more concepts in a software project? [closed]

I am trying to get my head around the concepts of a typical software project, but I cannot find a decent article concerning this.

  • What are factories?
  • What are services?
  • What are util classes?

  • And what are the key differences between them? (ex, what makes a factory not a service, etc)

  • And are there any more concepts in a software project that are common?

like image 629
corgrath Avatar asked Jan 17 '23 17:01

corgrath


1 Answers

A factory is an implementation of The Factory Pattern. It's a way of creating objects.

A service is class that manages the concerns of a particular aspect of you application. For example, if you application operated on People objects, you might have some sort of PersonService to manage all the concerns of creating, editing, deleting, etc. Multiple services can be used by other services to accomplish goals that touch upon more than one domain area of your app. For example, if a Person can be added to a Company, the PersonService and CompanyService can work together to do the necessary operations. Usually there would be another service like YourAppService that coordinates those two services. When you do this it is called The Facade Pattern.

A utility class is a class that holds operations that are general to your application. For example, say you need to use some regexes all over you app. You could have a TextUtil that operates on Strings and whatnot anywhere. In Java projects, I usually create a TestUtil class that has methods to create objects that I will use in unit tests (the test util is itself tested, too). You could consider this use case an implementation of the factory pattern.

Some people think that if you have utility classes that you use in your application, it is a symptom of bad design.

like image 107
hvgotcodes Avatar answered Jan 31 '23 19:01

hvgotcodes