Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 638 Bytes

File metadata and controls

32 lines (26 loc) · 638 Bytes

Data Abstraction

Data Abstraction violation:

class Book {
    constructor(pages) {
        this.pages = pages;
    }
}

const myBook = new Book([{ text: 'content of the title page'}, { text: '...'}]);
const titlePage = myBook.pages[0];

Fixed:

class Book {
    constructor(title, pages) {
        this.title = title;
        this.pages = pages;
    }

    getTitlePage() {
        return this.pages[0];
    }   
}

const myBook = new Book([{ text: 'content of the title page'}, { text: '...'}]);
const titlePage = myBook.getTitlePage();