How do you declare an interface in C++?

To expand on the answer by bradtgmurray, you may want to make one exception to the pure virtual method list of your interface by adding a virtual destructor. This allows you to pass pointer ownership to another party without exposing the concrete derived class. The destructor doesn’t have to do anything, because the interface doesn’t … Read more

Is List a subclass of List? Why are Java generics not implicitly polymorphic?

No, a List<Dog> is not a List<Animal>. Consider what you can do with a List<Animal> – you can add any animal to it… including a cat. Now, can you logically add a cat to a litter of puppies? Absolutely not. // Illegal code – because otherwise life would be Bad List<Dog> dogs = new ArrayList<Dog>(); … Read more

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

Quick answer: A child scope normally prototypically inherits from its parent scope, but not always. One exception to this rule is a directive with scope: { … } — this creates an “isolate” scope that does not prototypically inherit. This construct is often used when creating a “reusable component” directive. As for the nuances, scope … Read more

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

To summarize the contents of other (already good!) answers, isinstance caters for inheritance (an instance of a derived class is an instance of a base class, too), while checking for equality of type does not (it demands identity of types and rejects instances of subtypes, AKA subclasses). Normally, in Python, you want your code to … Read more

Why not inherit from List?

There are some good answers here. I would add to them the following points. What is the correct C# way of representing a data structure, which, “logically” (that is to say, “to the human mind”) is just a list of things with a few bells and whistles? Ask any ten non-computer-programmer people who are familiar … Read more

Calling the base constructor in C#

Modify your constructor to the following so that it calls the base class constructor properly: public class MyExceptionClass : Exception { public MyExceptionClass(string message, string extrainfo) : base(message) { //other stuff here } } Note that a constructor is not something that you can call anytime within a method. That’s the reason you’re getting errors … Read more

Prefer composition over inheritance?

Prefer composition over inheritance as it is more malleable / easy to modify later, but do not use a compose-always approach. With composition, it’s easy to change behavior on the fly with Dependency Injection / Setters. Inheritance is more rigid as most languages do not allow you to derive from more than one type. So … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)