Why aren’t static methods considered good OO practice? [closed]

Object-orientation is about three things: messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. Of those three, the most important one is messaging. Static methods violate at least messaging and late-binding. The idea of messaging means that in OO, computation is performed by networks of self-contained objects which send … Read more

Duck Typing in Javascript

The rule of “Duck Typing” is If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck. In a class-based object-oriented programming language (C++, for example) to make both objects look like a duck you must inherit their classes from a common “interface” class, so … Read more

Why doesn’t generic ICollection implement IReadOnlyCollection in .NET 4.5?

There are probably several reasons. Here are some: Huge backwards compatibility problems How would you write the definition of ICollection<T>? This looks natural: interface ICollection<T> : IReadOnlyCollection<T> { int Count { get; } } But it has a problem, because IReadOnlyCollection<T> also declares a Count property (the compiler will issue a warning here). Apart from … Read more

Why is it impossible to change constructor function from prototype?

You cannot change a constructor by reassigning to prototype.constructor What is happening is that Rabbit.prototype.constructor is a pointer to the original constructor (function Rabbit(){…}), so that users of the ‘class’ can detect the constructor from an instance. Therefore, when you try to do: Rabbit.prototype.constructor = function Rabbit() { this.jumps = “no”; }; You’re only going … Read more

Are C# properties actually Methods?

Yes, the compiler generates a pair of get and set methods for a property, plus a private backing field for an auto-implemented property. public int Age {get; set;} becomes the equivalent of: private int <Age>k__BackingField; public int get_Age() { return <Age>k__BackingField; } public void set_Age(int age) { <Age>k__BackingField = age; } Code that accesses your … Read more

Class with too many parameters: better design strategy?

UPDATE: This approach may be suited in your specific case, but it definitely has its downsides, see is kwargs an antipattern? Try this approach: class Neuron(object): def __init__(self, **kwargs): prop_defaults = { “num_axon_segments”: 0, “apical_bifibrications”: “fancy default”, … } for (prop, default) in prop_defaults.iteritems(): setattr(self, prop, kwargs.get(prop, default)) You can then create a Neuron like … Read more

adapter-Any real example of Adapter Pattern [closed]

Many examples of Adapter are trivial or unrealistic (Rectangle vs. LegacyRectangle, Ratchet vs. Socket, SquarePeg vs RoundPeg, Duck vs. Turkey). Worse, many don’t show multiple Adapters for different Adaptees (someone cited Java’s Arrays.asList as an example of the adapter pattern). Adapting an interface of only one class to work with another seems a weak example … Read more