2

Below is a reason which is given in a book to assigning a Factory helper class to delegate creation of objects due to complexity of object creations. That is "Conditionally creating of objects from one of a family of similar classes based upon some external property value". I cant figure out this situation. Can anyone help by giving an example for above.

2 Answers 2

4

At my company we deal with microphones and multiple platforms.

We have a factory method along the lines of createMicrophoneRecorderSource(...)

On Linux, we create an ALSA microphone. On Windows we use WASAPI and on iOS we use... native iOS stuff which I don't remember the exact name.

The user doesn't have to bother about knowing what is what, we hide all the gory details inside the factory.

Sign up to request clarification or add additional context in comments.

Comments

1

A factory is anything that makes an object. A constructor is already a factory. If you need other ways to make an object, you make more factories. Sometimes you make them outside the class itself, if the extra behavior depends on things the class shouldn't need to care about.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.