Tag : object-oriented

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I should declare the most abstract type as possible. However, in some cases I remember, especially for UI related codes, I can’t declare the most abstract type because those UI object usually require to run some child class specific functions, consider Label is a subclass of View in some UI framewor..

Read more

class ItemList { constructor() { this.list = [];//list holds many instances of Item Class } removeItem(id) { //…search for item in this.list, remove it } } class Item { constructor(parent) { this.id = 123456; this.parent = parent;//ItemList } removeSelf() { this.parent.removeItem(this.id); } } The item class is able to delete itself and the state of ..

Read more