Abstraction is an object-oriented concept that allows us to have a base class that delegates the implementation of a function to the class that extends the abstract
class.
The following example creates the main class by instantiating the custom logic class. It invokes the main function, which will execute the abstract
function. To the MainClass
class, the abstract
function is a black box. It only knows its name, parameter types, and returns types. The example executes the commented block code A-C-B in that particular order:
abstract class MainClass { public mainCoreLogic(): void { // Code here [A] this.delegatedLogic(); // Code here [B] } public abstract delegatedLogic(): void; } class CustomLogic extends MainClass { public delegatedLogic(): void { // Do some custom logic here [C] } } const c: MainClass = new CustomLogic(); c.mainCoreLogic();
The abstract
is powerful when you pass a computed value to the abstract
class and...