In this video, learn why you should avoid using complex constructors. Find out why the Builder pattern is a better alternative to the telescoping constructor pattern.
- [Instructor] The main purpose of the builder pattern…is to avoid having complex constructors.…In general, you should avoid having a constructor…that takes a large number of parameters.…Long lists of parameters are confusing…and do not give you much flexibility…when creating a class.…Consider the case of a class representing a person.…Each new person created will have…a unique combination of characteristics.…For example, each person will have a name, age,…hair color, eye color, occupation, nationality,…and so on and so forth.…
In a Java application, every time a person was created,…all of this information would have…to be passed into the constructor.…This is a very long list that needs to be supplied,…and it is easy to see how items might…be put in the wrong order.…There might also be times in the application…where not all of the information is needed.…You might need to create a person…but only want to specify their name.…To create a person you would still have to supply…all of the other information about their hair color,…
Released
8/29/2018- What are creational design patterns?
- Avoid complex constructors
- Implementing the Builder pattern
- Multithreading with the Singleton pattern
- Using the Prototype pattern
- Implementing a simple Factory Method pattern
- Making code more flexible with the Abstract Factory pattern
Share this video
Embed this video
Video: Avoid complex constructors