lsp

What is the Liskov Substitution Principle?

I have heard that the Liskov Substitution Principle (LSP) is a fundamental principle of object oriented design. What is it and what are some examples of its use? ...

C# Interface Implementation relationship is just "Can-Do" Relationship?

Today somebody told me that interface implementation in C# is just "Can-Do" relationship, not "Is-A" relationship. This conflicts with my long-time believing in LSP(Liskov Substitution Principle). I always think that all inheritance should means "Is-A" relationship. So, If interface implementation is just a "Can-Do" relationship. What ...

Interface inheritance: what do you think of this:

Hi When reviewing our codebase, I found an inheritance structure that resembles the following pattern: interface IBase { void Method1(); void Method2(); } interface IInterface2 : IBase { void Method3(); } class Class1 : IInterface2 { ... } class Class2 : IInterface2 { ... } class Class3 : IInterface2 { ... ...

Liskov Substition and Composition

Let say I have a class like this: public sealed class Foo { public void Bar { // Do Bar Stuff } } And I want to extend it to add something beyond what an extension method could do....My only option is composition: public class SuperFoo { private Foo _internalFoo; public SuperFoo() { _internalFo...

Zend_Form and Liskov Substitution Principle

A very common pattern I see (I'm picking on Zend Framework, only because I was dealing with it at the moment of this question), is something like this: class My_Form extends Zend_Form { public function init() { $this->addElement(); } } Zend_Form is not an abstract class, but is perfectly usable on its own. This see...

Is deriving square from rectangle a violation of Liskov's Substitution Principle?

I am new to design and learning the design principles. It says deriving square from rectangle is a classic example of violation of Liskov's Substitution Principle. If that's the case, what should be the correct design? ...

Why can't I use AddRange to add subclassed items?

I have two classes.... Parcel and FundParcel...and I'm trying to convert an IEnumerable of the subtype to an IList of the supertype.... public class FundParcel : Parcel { /* properties defined here */ } public class Parcel { /* properties defined here */ } These are used in another class in a method as follows: private IList<Par...

Type parameter constraints for the liskov principle in C#.NET

I try to create a generic interface that inherits the System.ICloneable interface but where the returntype of the Clone()-method is T. Of course the T-type needs constraints to be sure it's an inheritance of the System.Object-class but the following code is not working. public interface ICloneable<T> : System.ICloneable where T : object...

SOLID Liskov Substitution Principle

if i have something like class square : figure {} class triangle : figure {} does that mean that i should never ever use the square and triangle classes but only refer to figure ? like never do like this: var x = new square(); ...

Liskov substitution principle - no overriding/virtual methods?

My understanding of the Liskov substitution principle is that some property of the base class that is true or some implemented behaviour of the base class, should be true for the derived class as well. I guess this would mean when a method is defined in a base class, it should never be overrided in the derived class - since then substit...

Does the Liskov Substitution Principle apply to subtype which inherited from abstract class?

loosely speaking, Liskov Substitution Principle states that a derived class can be substitute in place of the base class without affecting the user. In the case when the base class is an abstract class, which means no user is using an instance of the base class, does the Liskov inheritance restrictions still apply to the derived class? ...

Type - Subtype relation. Something seems unclear.

I'm reading some slides of a class on object oriented programming languages and stepped into the type-subtype definition: Barbara Liskov, “Data Abstraction and Hierarchy,” SIGPLAN Notices, 23,5 (May, 1988): What is wanted here is something like the following substitution property: If for each object o_s of type S there is ...

How to detect SSL handshake with LSP?

Hi, how can i detect that application wants to establish ssl connection using LSP. I need to break that SSL handshake and detect the destination adress and port. Is that possible? I am using vc++. ...

How to develop something similar to LSP for Mac OSX

Microsoft provides the Layered Service Provider as part of Winsock 2 which makes it relatively easy to develop a user-mode network filter. I am looking to port an HTTP content filter LSP to Mac OSX, and am looking for ways to do the implementation. Is there any similar interface in Mac OSX, or is this something that can only be done at t...

Layered service provider(LSP) SSL handshake detection

Hi,i am interesting in detection SSL handshake with layered service proveder. I have a nonifs LSP. I dont know how it is possible but when i write the function WSPSend buffer when in browser requesting https site. I see only encrypted data(no plain text). But its clearly said in ssl handshake, that browser at first sends hallo message ...

Does using virtual methods violates LSP( L part of SOLID principles) or there are some exceptions?

Hi all, Does using virtual methods violates LSP( L part of SOLID principles) or there are some exceptions? Thanks in advance, Saghar Ayyaz ...

Need help with .Net SOLID design

I'm trying to stick fast to Robert Martin's SOLID design principles for the first time, and I am not good at it. In essence, I need a hierarchy of "Node" objects. Some nodes are NodeHosts, some are NodeChildren and some are Both. Everybody's done this one before, but I can't figure out how to do it SOLID without over-complicating the ...

Liskov Substitution Principle and the directionality of the original statement

I came across the original statement of the Liskov Substitution Principle on Ward's wiki tonight: What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is subs...

Example of extending a class

I am looking for few examples of class extension without Lyskov Substitution Principle violation, where class being extended is not a template/abstract/skeleton class, and extending class isn't just a decorator. ...

Is the ReadOnlyCollection class a good example of Bad Design?

Look at the specification of the ReadOnlyCollection class, it does implements the IList interface, right. The IList interface have Add/Update/Read methods, which we call it pre-conditions of the interface. Anywhere in my application if I have an IList I should be able to do all this kind of operations. But what about if I return a Rea...