พูดว่าฉันมี:
interface Thing
{
GetThing();
}
class FastThing : Thing
{
public int GetThing()
{
return 1;
}
}
class SlowThing : Thing
{
public int GetThing()
{
return GetThingFromDatabase();
}
}
นี่เป็นการละเมิดหลักการทดแทน Liskov หรือไม่?
FastThingด้วยSlowThingLSP จะไม่สามารถใช้งานได้ หากคุณเพิ่มความคิดเห็นThing::GetThingที่ระบุว่า "เร็วมาก" คุณสามารถพูดคุยคำถามได้
GetThingFromDatabase()ไม่ช้าพอที่จะทำให้การโต้เถียงนี้Factor4096BitPublicKey();return 1;จะทำให้สิ่งต่าง ๆ น่าสนใจยิ่งขึ้น