Implementing data entities and interfaces
In this section, I will demonstrate how you can use classes in your own code design to define and encapsulate the behavior of your models, such as the User
class. Later in this chapter, you will see examples of class inheritance with abstract base classes, which allows us to standardize our implementation and reuse base functionality in a clean and easy-to-maintain manner.
I must point out that OOP has very useful patterns that can increase the quality of your code; however, if you overuse it, then you will start losing the benefits of the dynamic, flexible, and functional nature of JavaScript.
Sometimes, all you need is a bunch of functions in a file, and you’ll see examples of that throughout the book.
A great way to demonstrate the value of classes would be to standardize the creation of a default User
object. We need this because a BehaviorSubject
object needs to be initialized with a default object. It...