// code from http://prasadhonrao.com/solid-principles-liskov-substitution-principle-lsp/ | |
Rectangle rect = new Rectangle(); | |
rect.SetHeight(10); | |
rect.SetWidth(5); | |
System.Console.WriteLine(rect.CalculateArea()); // Kết quả là 5 * 10 | |
// Below instantiation can be returned by some factory method | |
Rectangle rect1 = new Square(); | |
rect1.SetHeight(10); | |
rect1.SetWidth(5); | |
System.Console.WriteLine(rect1.CalculateArea()); | |
// Kết quả là 5 x 5. Nếu đúng phải là 10x5, vì diện tích 1 hình chữ nhật là dài x rộng | |
// Class Square sửa hành vi của class cha Rectangle, set cả dài và rộng về 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment