Constructors in Go

There are some equivalents of constructors for when the zero values can’t make sensible default values or for when some parameter is necessary for the struct initialization. Supposing you have a struct like this : type Thing struct { Name string Num int } then, if the zero values aren’t fitting, you would typically construct … Read more

Switch statements are bad? [closed]

A switch is like any other control structure. There are places where it’s the best/cleanest solution, and many more places where it’s completely inappropriate. It’s just abused way more than other control structures. In OO design, it’s generally considered preferable in a situation like yours to use different message types/classes that inherit from a common … 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

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

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