TypeScript

abstract class

Classes, methods, and fields in TypeScript may be abstract. An abstract method or abstract field is one that hasn’t had an implementation provided. These members must exist inside an abstract class, which cannot be directly instantiated. The role of abstract classes is to serve as a base class for subclasses which do implement all the abstract members. When a class doesn’t have any abstract members, it is said to be concrete.

抽象类,可以 提供默认实现 的 类型描述。
抽象类与接口的区别在于,接口常用于描述某个行为及与之相关的属性(一个接口描述的可以是代表整体上部分的内容,如 鸟,飞 是鸟的部分内容),且只有类型,无实现。
而一个抽象类与类相同,用于描述一个整体也叫 对象,需描述完全这个对象 所有的行为与属性。但抽象类可以不实现,只提供类型。

  1. abstract class Base {
  2. abstract getName(): string;
  3. printName() {
  4. console.log("Hello, " + this.getName());
  5. }
  6. }
  7. const b = new Base(); // Cannot create an instance of an abstract class.
  8. class Derived extends Base {
  9. getName() {
  10. return "world";
  11. }
  12. }
  13. const d = new Derived();
  14. d.printName();

未实现的属性,用 abstract 做前缀。不可 new,需用 类 extends 后使用。

pattern

helper

https://softwareengineering.stackexchange.com/questions/247267/what-is-a-helper-is-it-a-design-pattern-is-it-an-algorithm

At least in my convention, the utility class is static-only methods without any dependencies, while the helper has dependencies, and therefore has non-static methods.

Programming

TTY