
Constructors And Initializers In Object-Oriented Design
When we create an instance of a class, we often need to do some initialization. Constructors and initializers achieve this goal. These are two different ways to get our data into an instance and are an essential part of our design. In this episode, we examine the design decisions we need to make as we decide how to use these common methods. Constructors And Initializers – The Distinction A constructor and an initializer method can be thought of in very similar ways. However, there is one particular trait that differs between the two approaches. A constructor returns an instance of a class, whereas an initializer sets values on an instance. This may seem to be a minor difference. It is... Read more