What (and the difference between) factories, service and use classes? Are there any other concepts in a software project?

I'm trying to figure out the concepts of a typical software project, but I can't find a decent article on this.

  • What are factories?
  • What are services?
  • What are usage classes?

  • And what are the main differences between the two? (for example, what makes a factory not a service, etc.)

  • And are there any other concepts in the software project that are common?

+2
source share
1 answer

A factory is an implementation of a factory pattern . This is a way to create objects.

A service is a class that manages the problems of a particular aspect of your application. For example, if the application runs on People objects, you may have some kind of PersonService to manage all problems when creating, editing, deleting, etc. Several services can be used by other services to achieve goals that affect more than one area of ​​your application. For example, if a Person can be added to Company , PersonService and CompanyService can work together to perform the necessary operations. There will usually be another service, such as YourAppService , which coordinates the two services. When you do this, it is called "Facade . "

A utility class is a class that contains operations common to your application. For example, let's say you need to use some regular expressions throughout the application. You may have a TextUtil that works with Strings and nowhere else. In Java projects, I usually create the TestUtil class, which has methods for creating objects that I will use in unit tests (the test itself is also checked). You can consider this use case as an implementation of a factory pattern.

Some people think that if you have utility classes that you use in your application, this is a sign of poor design.

+5
source

Source: https://habr.com/ru/post/981184/


All Articles