Challenge: Solution Review
Explore how to apply the abstract creational pattern to dynamically instantiate different types of loan objects in JavaScript. Learn how constructors for personal, student, and home loans encapsulate properties and methods for calculating interest, simplifying object creation while enhancing code organization.
We'll cover the following...
Solution #
Explanation
To make the problem easier to understand, let’s start by converting it to a diagram.
If you follow the diagram and the code, you’ll see that there is an abstract Loans constructor function. Its purpose is to instantiate an instance of a specific loan constructor, depending on the parameters given.
From the diagram above, you can see that three types of loan objects can be instantiated:
-
PersonalLoan -
StudentLoan -
HomeLoan
These loans, in turn, have different types available. In our coding challenge, we do not go into these subcategories. However, knowing this will ...