What is the difference between factory classes and useful classes?

What is the difference between factory classes and useful classes? When do we use the factory method and when do we use utility classes?

+6
source share
3 answers

From Wikipedia

In object-oriented programming, a factory β€” an object to create other objects β€” formally a factory β€” is simply an object that returns an object from some method call that is considered "new." Factory method template

In computer programming, a utility class is a class that defines a set of methods that perform common, often reused functions. Most of the utility classes define these common methods under static (see Static Variable) scope. Utility

I think you can guess the answer :)

+2
source

Factory design template: -
In the Factory template, we create an object without exposing the creation logic to the client and referring to the newly created object using a common interface.
Utility classes: -
a useful class consists solely of static methods that work with collections or return them

0
source

Basicaly, factory is used to create an object (for example, for viewing), you can create another object with one factory with different requests that you can execute

A class utility is a class with static methods that you call to perform some operation (for example, some complicated operation involving manipulating numbers or strings), but regardless of another class.

I read that using the Utility class is bad programming, but I disagree with that

0
source

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


All Articles