Linked Questions

-2 votes
2 answers
343 views

My sample program like below; public class Animal { public virtual string MakeSound() { return "General Sound"; } } public class Dog : Animal {...
Akhil's user avatar
  • 2,050
3 votes
0 answers
176 views

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 ...
Kenan's user avatar
  • 31
0 votes
1 answer
96 views

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 ...
beginpluses's user avatar
715 votes
14 answers
329k views

What does the expression "Turing Complete" mean? Can you give a simple explanation, without going into too many theoretical details?
dlinsin's user avatar
  • 19.6k
182 votes
21 answers
164k views

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 ...
michael's user avatar
  • 1,949
215 votes
13 answers
57k views

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?
Dustman's user avatar
  • 5,339
204 votes
10 answers
306k views

What is the difference between syntax and semantics in programming languages (like C, C++)?
haccks's user avatar
  • 107k
111 votes
12 answers
21k views

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 ...
Brian Rasmussen's user avatar
80 votes
12 answers
31k views

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 ...
hasen's user avatar
  • 167k
72 votes
6 answers
12k views

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....
Aishwar's user avatar
  • 9,754
51 votes
7 answers
24k views

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 ...
Ricky's user avatar
  • 10.5k
56 votes
5 answers
90k views

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 ...
helpermethod's user avatar
  • 62.8k
43 votes
5 answers
24k views

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 ...
random512's user avatar
  • 1,093
33 votes
10 answers
21k views

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 ...
Igor's user avatar
  • 27.4k
30 votes
8 answers
2k views

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 ...
Gene C's user avatar
  • 2,030
43 votes
4 answers
20k views

Can anyone explain the concept of covariance and contravariance in programming language theory?
xdevel2000's user avatar
  • 21.6k
36 votes
8 answers
5k views

I have seen many people in the Scala community advise on avoiding subtyping "like a plague". What are the various reasons against the use of subtyping? What are the alternatives?
missingfaktor's user avatar
60 votes
2 answers
9k views

There are claims that Scala's type system is Turing complete. My questions are: Is there a formal proof for this? How would a simple computation look like in the Scala type system? Is this of any ...
Adrian's user avatar
  • 3,832
34 votes
3 answers
15k views

Is there any core difference between Liskov Substitution Principle (LSP) and Interface Segregation Principle (ISP)? Ultimately, both are vouching for designing the interface with common ...
Nilanjan Saha's user avatar
11 votes
11 answers
22k views

I have seen few Pet and Dog type examples for this type of basic question here and here, but they do not make sense to me, here is why. Suppose we have the following class structure class Pet {}; ...
Lazer's user avatar
  • 95.9k
30 votes
5 answers
4k views

Here's a couple of snippets: Overriding constructor method has an extra parameter. class Cat { function __construct() {} } class Lion extends Cat { function __construct($param) {} } ...
Emanuil Rusev's user avatar
21 votes
10 answers
8k views

I understand that virtual methods allow a derived class to override methods inherited from a base class. When is it appropriate/inappropriate to use virtual methods? It's not always known whether or ...
Maxpm's user avatar
  • 26.1k
22 votes
5 answers
7k views

I apologize for the subjectiveness of this question, but I am a little stuck and I would appreciate some guidance and advice from anyone who's had to deal with this issue before: I have (what's ...
Ash's user avatar
  • 25.9k
23 votes
4 answers
15k views

I am having trouble with the concept of interfaces interacting with polymorphic types (or even polymorphic interfaces). I'm developing in C# and would appreciate answers staying close to this ...
hannasm's user avatar
  • 2,041
21 votes
6 answers
1k views

List("a").contains(5) Because an Int can never be contained in a list of String, this should generate an error at compile-time, but it does not. It wastefully and silently tests every String ...
Shelby Moore III's user avatar
13 votes
4 answers
12k views

I have a situation where I need to modify the super class method to have a subclass specific logic, but the methods logic is same for all other subclasses. I have two options: 1) make the method ...
Learner's user avatar
  • 569
8 votes
3 answers
4k views

I have following class: public class Publisher<T> { private static final Class[] SUPPORTED_CLASSES = new Class[]{T1.class, T2.class}; public Publisher() { if(Arrays.asList(...
FazoM's user avatar
  • 4,966
12 votes
3 answers
12k views

Is it possible to wrap text around a non rectangular image? I want text around maps of different countries to wrap around the country's shape in such a way that the text always keeps the same ...
Che Kofif's user avatar
  • 861
16 votes
2 answers
9k views

What is the best way to unit test subclasses? Let's assume there's a base class for which I've already written tests and there are some number of subclasses that override some of the parent's ...
DRock's user avatar
  • 285
14 votes
3 answers
2k views

I want to have a certain kind of std::vector that cannot have more than const int MAX_LENGTH elements. I understand that I cannot override std::vector non-virtual functions, which I'd need to do to ...
helloB's user avatar
  • 3,622

15 30 50 per page
1
2 3 4 5
7