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

Should you ever use protected member variables?

Should you ever use protected member variables? Depends on how picky you are about hiding state. If you don’t want any leaking of internal state, then declaring all your member variables private is the way to go. If you don’t really care that subclasses can access internal state, then protected is good enough. If a … Read more

How to create a “single dispatch, object-oriented Class” in julia that behaves like a standard Java Class with public / private fields and methods

While of course this isn’t the idiomatic way to create objects and methods in julia, there’s nothing horribly wrong with it either. In any language with closures you can define your own “object systems” like this, for example see the many object systems that have been developed within Scheme. In julia v0.5 there is an … Read more

Why encapsulation is an important feature of OOP languages? [closed]

Encapsulation helps in isolating implementation details from the behavior exposed to clients of a class (other classes/functions that are using this class), and gives you more control over coupling in your code. Consider this example, similar to the one in Robert Martin’s book Clean Code: public class Car { //… public float GetFuelPercentage() { /* … Read more

What is immutability and why should I worry about it?

What is Immutability? Immutability is applied primarily to objects (strings, arrays, a custom Animal class) Typically, if there is an immutable version of a class, a mutable version is also available. For instance, Objective-C and Cocoa define both an NSString class (immutable) and an NSMutableString class. If an object is immutable, it can’t be changed … Read more

If-less programming (basically without conditionals) [closed]

There are some resources on the Anti-IF Campaign site, such as this article. I believe it’s a matter of degree. Conditionals aren’t always bad, but they can be (and frequently are) abused. Additional thoughts (one day later) Refactoring: Improving the Design of Existing Code is a good reference on this subject (and many others). It … Read more

Mixin vs inheritance

A mixin is typically used with multiple inheritance. So, in that sense, there’s “no difference”. The detail is that a mixin is rarely useful as a standalone object. For example, say you have a mixin named “ColorAndDimension”, which adds a color property and width and height. Now, you could add ColorAndDimension to a, say, Shape … Read more

Differences between Proxy and Decorator Pattern

The real difference is not ownership (composition versus aggregation), but rather type-information. A Decorator is always passed its delegatee. A Proxy might create it himself, or he might have it injected. But a Proxy always knows the (more) specific type of the delegatee. In other words, the Proxy and its delegatee will have the same … Read more

tech