Linked Questions
196 questions linked to/from What is an example of the Liskov Substitution Principle?
-2 votes
2 answers
343 views
Understanding Liskov Substituion Principle [duplicate]
My sample program like below; public class Animal { public virtual string MakeSound() { return "General Sound"; } } public class Dog : Animal {...
3 votes
0 answers
176 views
polymorphism: why would you assign a interface reference to a subclass of superclass that implements the interface [duplicate]
i'm trying to understand the basics of polymorphism. I do understand why it could be useful to assign a superclass to a sub class or a sub to a super. what i don't understand quite well is the logic ...
0 votes
1 answer
96 views
What does Liskov Substitution Principle preserve? [duplicate]
As I've read the substitution of objects of a concrete type by instances of a subclass of that concrete type must preserve a program's correctness, a program's invariants. I'd like to know what ...
715 votes
14 answers
329k views
What is Turing Complete?
What does the expression "Turing Complete" mean? Can you give a simple explanation, without going into too many theoretical details?
182 votes
21 answers
164k views
Assignment in an if statement
I have a class Animal, and its subclass Dog. I often find myself coding the following lines: if (animal is Dog) { Dog dog = animal as Dog; dog.Name; ... } For the variable Animal ...
215 votes
13 answers
57k views
What is an invariant?
The word seems to get used in a number of contexts. The best I can figure is that they mean a variable that can't change. Isn't that what constants/finals (darn you Java!) are for?
204 votes
10 answers
306k views
What is the difference between syntax and semantics in programming languages?
What is the difference between syntax and semantics in programming languages (like C, C++)?
111 votes
12 answers
21k views
Design patterns to avoid [closed]
A lot of people seem to agree, that the Singleton pattern has a number of drawbacks and some even suggest avoiding the pattern entirely. There's an excellent discussion here. Please direct any ...
80 votes
12 answers
31k views
How to design extensible software (plugin architecture)? [closed]
I need some resources that talk about how to design your software to be extensible, i.e. so that other people can write add-ons/plug-ins that adds functionality to it. What do you recommend? Any ...
72 votes
6 answers
12k views
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....
51 votes
7 answers
24k views
What are the differences between functions and methods in Swift?
I always thought functions and methods were the same, until I was learning Swift through the "Swift Programming Language" eBook. I found out that I cannot use greet("John", "Tuesday") to call a ...
56 votes
5 answers
90k views
Mocking a class vs. mocking its interface
For a unit test, I need to mock several dependencies. One of the dependencies is a class which implements an interface: public class DataAccessImpl implements DataAccess { ... } I need to set up ...
43 votes
5 answers
24k views
Can anyone provide an example of the Liskov Substitution Principle (LSP) using Vehicles?
The Liskov Substitution Principle states that a subtype should be substitutable for that type (without altering the correctness of the program). Can someone please provide an example of this principle ...
33 votes
10 answers
21k views
Inheritance or composition: Rely on "is-a" and "has-a"?
When I design classes and have to choose between inheritance and composition, I usually use the rule of thumb: if the relationship is "is-a" - use inheritance, and if the relationship is "has-a" - use ...
30 votes
8 answers
2k views
What is wrong with testing an object to see if it implements an interface?
In the comments of this answer it is stated that "checking whether the object has implemented the interface , rampant as it may be, is a bad thing" Below is what I believe is an example of this ...