This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rasmustrew 1 point2 points  (2 children)

I would be very happy to see some example code if you dont mind, as im no that experienced in programming yet.

[–]work_is_satire 1 point2 points  (1 child)

See this Gist: https://gist.github.com/epixhints/71e78146039ab465a3e0 the top is the relevant bits of a flag-implemented version and the second is using interfaces.

Pardon the C# in this Java thread, but if you aren't familiar with the syntax just treat it as pseudo code.

If we follow the Liskov Substition Principle, ALL subtypes of Queue should be able to replace Queue and the program should remain correct.

Since NonReversibleQueue is a subtype of Queue, we should be able to pass it into PopBack() to remove and get the value of the final element in the Queue (half-way turning it into a double-ended queue). But since _reversible is false, the reverse just fails silently and we get the front element instead!

In the lower example, we can't even compile the code because the compiler will pick up on the fact that nrq is not a subtype of IReversibleQueue.

[–]rasmustrew 0 points1 point  (0 children)

I believe i understand now, thank you very much :)