Conversation started Dec 29, 2015 at 17:34.
Dec 29, 2015 17:34
25
A: What can go wrong if the Liskov substitution principle is violated?

Jimmy HoffaI think it's stated very well in that question which is one of the reasons that was voted so highly. Now when calling Close() on a Task, there is a chance the call will fail if it is a ProjectTask with the started status, when it wouldn't if it was a base Task. Imagine if you will: pub...

2
A: Does the state Pattern violate Liskov Substitution Principle?

Jimmy HoffaThis particular implementation, yes. If you make the states concrete classes rather than abstract implementors then you will get away from this. However the state pattern you're referring to which is effectively a state machine design is in general something I disagree with from the way I've see...

Well, you have it backwards with Python. Most all type-checking should be done with isinstance.
hm, to me that doesn't sound like a misinterpretation of LSP so much as completely missing the point of using inheritance and thus ignoring LSP
in C++-like that would be considered an anti-pattern and rejected at codereview
@AaronHall LSP is about contract demands: You may not strengthen preconditions or weaken post-conditions
Dec 29, 2015 17:35
we use virtual dispatch; we don't hardcode type names and switch on that
-1
Q: Single cout statement

DanielPlease am learning C++ for the first time. Can someone help me with this Write a program to display the following output using a single cout statement ◦ English: 50 ◦ Maths: 75 ◦ ICT: 90 Thanks

heavens.
Most people coming from other languages to Python are checking type with type(obj) == str or whatever class/type.
[citation needed]
also it's worth noting that "most" != "competent"
I realise people do that a lot but, well, they shouldn't
I guess if you're talking about verifying that your arguments are integers/strings/objects/etc like they should be, then sure
If you need to check type in Python, you use isinstance(obj, str) or better, an abstract base class.
to me "isinstance" is testing which concrete implementation of an interface an object happens to be, which is definitely a code smell in every language
in JS I'd check for an interface by simply asserting that obj.foo is a function rather than undefined, or something like that
Dec 29, 2015 17:37
So to follow LSP, a method meeting one contract cannot require more or less pre-work than a method in another contract, as well as it may not cause the state of the system after it's exit to be coercively more or less able than any other implementor of the contract. For example: If you have a contract that requires open, read, write, and close where open has to be done before read or write, if one implementor doesn't require open first, it is violating LSP.
If one implementor closes after reading or writeing when the contract requires that both read and write leave the state unchanged, then that implementor violated LSP
LSP is all about making it so that your code works on one contract and if you substitute other instances in place - your code won't break
Like, if you need to ensure you have a dict type object that you won't modify, you check for type with isinstance(obj, Mapping) where Mapping is from the collections module
so if you open() then read() then close() and one instance close()s on it's own after read() your code will throw an exception when you get an instance of that type vs. other types that don't close() automatically
 
Conversation ended Dec 29, 2015 at 17:38.