Stack, bounded stack and Liskov substitution property?

Liskov substituion princple is stated as Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T Let us say T is type Stack and S is a subtype of T of type BoundedStack Now, let us define q(x) as the capacity of stack x If x is an instance of T then the capacity is infinite/boundless. If x is an instance of S then this does not hold as the capacity is now bounded Therefore the principle does not hold.

Liskov substituion princple is stated as Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. Let us say T is type Stack and S is a subtype of T of type BoundedStack.

Now, let us define q(x) as the capacity of stack x. If x is an instance of T then the capacity is infinite/boundless. If x is an instance of S then this does not hold as the capacity is now bounded.

Therefore the principle does not hold.

Great, that all makes sense. Thanks. – Lee Jun 1 at 10:48 @monkjack: Is the capacity boundless, or is it simply ill-defined?

If the capacity is ill-defined, why wouldn't a class with defined capacity and defined behavior on overflow be substitutable for one where neither the real capacity nor the overflow behavior were specified? – supercat Sep 12 at 21:58.

Obviously bounded stack will generate a new type of exception for push method. So it does not comply LSP.

If there were really such a thing as an unbounded stack, a bounded stack would not be a subtype of it. On the other hand, the semantics of a "conventional" stack are probably more like "If the number of objects pushed doesn't exceed some vague, unknowable, and arbitrarily-variable limit, push the object; otherwise fail in some arbitrary and undefined fashion. " If a regular stack provides a Count property and promises that any stack whose Count is 1,000 or less will be able to accept another item, a bounded stack with a capacity of 1,000 or greater would be fully substitutable for the "conventional" one.

If it doesn't make any particular promise of capacity, a bounded stack with any capacity would be substitutable.

Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. Let us say T is type Stack and S is a subtype of T of type BoundedStack.

Now, let us define q(x) as the capacity of stack x. If x is an instance of T then the capacity is infinite/boundless. If x is an instance of S then this does not hold as the capacity is now bounded.

Therefore the principle does not hold.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions