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: 
            this._identifier = Math.random().toString(36). substr(2,9); ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.