The simplest solution is to extend the base House class and create a set of subclasses to cover all combinations of the parameters. But what if you want a bigger, brighter house, with a backyard and other goodies (like a heating system, plumbing, and electrical wiring)? To build a simple house, you need to construct four walls and a floor, install a door, fit a pair of windows, and build a roof. You might make the program too complex by creating a subclass for every possible configuration of an object.įor example, let’s think about how to create a House object. Or even worse: scattered all over the client code. Such initialization code is usually buried inside a monstrous constructor with lots of parameters. Imagine a complex object that requires laborious, step-by-step initialization of many fields and nested objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |