All Questions

568
votes
16answers
131266 views

What is object slicing?

Someone mentioned it in the IRC, but google doesn't have a good answer.
108
votes
2answers
11981 views

Prototypical inheritance - writing up

So I have these 2 examples, from javascript.info: Example 1: var animal = { eat: function() { alert( "I'm full" ) this.full = true } } var rabbit = { jump: function() { /* something *...
553
votes
12answers
80907 views

Is List<Dog> a subclass of List<Animal>? Why are Java generics not implicitly polymorphic?

I'm a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy - Animal (Parent) Dog - Cat (Children) So suppose I have a method doSomething(List<A...
926
votes
3answers
137671 views

What are the nuances of scope prototypal / prototypical inheritance in AngularJS?

The API Reference Scope page says: A scope can inherit from a parent scope. The Developer Guide Scope page says: A scope (prototypically) inherits properties from its parent scope. So, doe...
1270
votes
33answers
227580 views

Prefer composition over inheritance?

Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition?
1777
votes
7answers
1167479 views

Understanding Python super() with __init__() methods

I'm trying to understand the use of super(). From the looks of it, both child classes can be created, just fine. I'm curious to know about the actual difference between the following 2 child classes...
301
votes
7answers
94119 views

What's wrong with overridable method calls in constructors?

I have a Wicket page class that sets the page title depending on the result of an abstract method. public abstract class BasicPage extends WebPage { public BasicPage() { add(new Label("t...
117
votes
3answers
16149 views

Why do I have to access template base class members through the this pointer?

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this->x. Why? template <typename T> class base { protected: ...
744
votes
16answers
519554 views

Difference between private, public, and protected inheritance

What is the difference between public, private, and protected inheritance in C++? All of the questions I've found on SO deal with specific cases.
826
votes
5answers
494598 views

What are the differences between type() and isinstance()?

What are the differences between these two code fragments? Using type(): import types if type(a) is types.DictType: do_something() if type(b) in types.StringTypes: do_something_else() Usin...

Previous Next