Why are interfaces preferred to abstract classes?

That interview question reflects a certain belief of the person asking the question. I believe that the person is wrong, and therefore you can go one of two directions. Give them the answer they want. Respectfully disagree. The answer that they want, well, the other posters have highlighted those incredibly well. Multiple interface inheritance, the … Read more

When is using __call__ a good idea?

I think your intuition is about right. Historically, callable objects (or what I’ve sometimes heard called “functors”) have been used in the OO world to simulate closures. In C++ they’re frequently indispensable. However, __call__ has quite a bit of competition in the Python world: A regular named method, whose behavior can sometimes be a lot … Read more

How to inherit static methods from base class in JavaScript?

In the classical (OO) inheritance pattern, the static methods do not actually get inherited down. Therefore if you have a static method, why not just call: SuperClass.static_method() whenever you need it, no need for JavaScript to keep extra references or copies of the same method. You can also read this JavaScript Override Patterns to get … Read more

Should internal class methods return values or just modify instance variables?

Returning a value is preferable as it allows you to keep all the attribute modifying in one place (__init__). Also, this makes it easier to extend the code later; suppose you want to override _build_query in a subclass, then the overriding method can just return a value, without needing to know which attribute to set. … Read more

Is method hiding ever a good idea

There are rare, but very good, reasons to use method hiding. Eric Lippert posted a great example on his blog: interface IEnumerable<T> : IEnumerable { new IEnumerator<T> GetEnumerator(); } However, I think hiding should be the exception, and only used sparingly.

Pass additional parameters to jQuery each() callback

You should be able to create a reference to your survey before you iterate over the questions. function Survey() { this.questions = new Array(); var survey = this; $(‘.question’).each(function(i) { survey.questions.push(new Question(this)); }); } function Question(element) { this.element = $(element); } var survey = new Survey(); $.each(survey.questions, function() { $(“ul”).append(“<li>” + this.element.text() + “</li>”); }); … Read more