User class and object-oriented programming
So far, we have only worked with interfaces to represent data, and we still want to continue using interfaces when passing data around various components and services. However, there's a need to create a default object to initialize a BehaviorSubject
. In Object-oriented Programming (OOP), it makes a lot of sense for the User
object to own this functionality instead of a service. So, let's implement a User
class to achieve this goal.
Inside the user/user
folder, define an IUser
interface and a User
class provided in UserModule
:
src/app/user/user/user.ts
import { Role } from '../../auth/role.enum'
export interface IUser {
id: string
email: string
name: {
first: string
middle: string
last: string
}
picture: string
role: Role
userStatus: boolean
dateOfBirth: Date
address: {
line1: string
line2: string
city: string
state: string
zip: string
}
phones: IPhone[]
}
export interface IPhone {
type: string...