Implementing the domain model

First of all, let's define our Genre enum. We'll use a string enum since this will be the easiest to understand:

enum Genre { 
    Horror = "Horror", 
    Fantastic = "Fantastic", 
    Thriller = "Thriller", 
    Romance = "Romance", 
    Fiction = "Fiction" 
} 

Next, we can implement the base Media class:

abstract class Media { 
    private _identifier: string; 
 
    protected constructor( 
        private _name: string, 
        private _description: string, 
        private _pictureLocation: string, 
        private _genre: Genre, 
        identifier?: string, 
    ) { 
        if (identifier) { 
            this._identifier = identifier; 
        } else { 
            // this is just for the example; for any real project, use 
            // UUIDs instead: https://www.npmjs.com/package/uuid 
            this._identifier = Math.random().toString(36). substr(2,9); ...

Get Learn TypeScript 3 by Building Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.