我怎样才能使这个小伪代码符合 Liskov 原则?

How can I make this small pseudocode comply with Liskov principle?

为了保持整洁和简单,这里是我最初的 Java 伪代码示例:

public abstract class Vehicle {        
     private String owner;
     private id plate;

     public removeVehicle() {
         if (typeof(this) == Car) {this.removeCar();}
         if (typeof(this) == Truck) {this.removeTruck();}
     }
}

public class Car extends Vehicle {
     public removeCar() {
        this.removeVehicle(this);
     }
}

public class Truck extends Vehicle {
     public removeTruck() {
        this.removeVehicle(this);
     }         
}

从书上说Agile principles patterns and practices in C# by Robert, Micah Martin不符合里氏原理,因为Vehicle,为了去除其他车辆类型(例如Motorcicle),需要扩展代码和为这种新型车辆添加另一个 if 声明。

我尝试遵循 here 提供的解决方案,但大多数只是从我刚刚引用的书中摘录,我正在积极尝试正确理解。

如何修改此伪代码使其符合 Liskov?

根据

"Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it."

https://en.wikipedia.org/wiki/SOLID

您的练习目标可以是将 class Vehicle 中的 removeVehicle 定义为 abstract 并在扩展 Vehicle 的 类 中实现它。