lsp

    39热度

    6回答

    我对Liskov替换原理的理解是,对于派生类,基类的某些属性为true或某些已实现的基类的行为也应该为真。 我想这将意味着当一个方法在基类定义,它不应该在派生类overrided - 从那以后代的基类,而不是派生的类会给出不同的结果。我猜这也意味着,拥有(非纯粹的)虚拟方法是一件坏事? 我想我可能对原理有一个错误的理解。如果我不这样做,我不明白为什么这个原则是好的做法。谁可以给我解释一下这个?谢谢

    2热度

    2回答

    如果我有像 class square : figure {} class triangle : figure {} 这是否意味着我永远也不会用方形和三角形类,但只涉及数字呢? 从来没有像这样做: var x = new square();

    0热度

    2回答

    我有两个类....包裹和FundParcel ......,我想一个IEnumerable转换的子类型的超类型的一个IList的.... public class FundParcel : Parcel { /* properties defined here */ } public class Parcel { /* properties defined here

    2热度

    2回答

    一个很常见的模式我看到(我捡上Zend框架,只是因为我与它在这个问题的处理时刻),是这样的: class My_Form extends Zend_Form { public function init() { $this->addElement(); } } Zend_Form不是一个抽象类,但它本身是完全可用的。这似乎是“推荐”的地方,将你的表格“封装”

    1热度

    1回答

    我尝试创建继承System.ICloneable接口的通用接口,但Clone()方法的返回类型是T.当然,T型需要约束要确定它是System.Object类的继承,但下面的代码不起作用。 public interface ICloneable<T> : System.ICloneable where T : object { T Clone(); } 我在做什么错? 而且下面的

    9热度

    2回答

    让说我有一个这样的类: public sealed class Foo { public void Bar { // Do Bar Stuff } } 而且我希望把它扩大到添加的东西超出了一个扩展方法可以做....我唯一的选择是组成: public class SuperFoo { private Foo _internalFoo;