New answers tagged

1

There is a general principle in object oriented programming: Any classes related to animals or vehicles are usually very bad examples that will make you cringe if you read through them in a year or two. An interface in Java defines a set of methods that any class might implement or not. If a Java class implements all the methods in the interface, and then ...


1

From what I get, you are torn between 2 possible ways to implement the same idea. Separated classes for const and mutable wrappers over the same interface. Reader/Writer approach where you separate the ability to write on fields with different interface classes. From a performance perspective I expect similar results so the choice is purely aesthetical. ...


1

I would prefer the second option. It is similar to iterator and const_iterator types provided by containers. Your wariness about constness of the wrapper is equally applicable to iterators and pointers. You can have mutable_record_wrapper inherit const_record_wrapper, which removes some of the boilerplate. class const_record_wrapper : public ...


8

Any interface definition that isn't specific enough to determine whether a client or service implementation conforms to it is not well-defined. Some examples: unspecified character encoding (one side using utf-8 while the other uses iso8859-1) unspecified number representation (decimal point versus comma) implicit sequencing requirements (need to call ...


1

The type systems of Python on the one hand and C# and Java on the other hand work in a fundamentally different way. C# and Java use a nominal type system: Two types are the same if they have the same name. Additionally, they use strong typing: assignment (and parameter passing) between references is only allowed if the target type is in the set of types ...


3

Returning maps (key-value stores) from non-private methods (in PHP arrays are implemented as hash tables), should the returned map represent a complex object, is really not a good idea in ANY language, not only in PHP. On a private level, where the scope of the type is limited to a given class, this is acceptable to a certain degree, although even then it's ...


1

This particular blind spot of programmers, especially object-oriented programmers, has always fascinated me. People think of reusability as something you always want to strive for in the future, and neglect that they are at this very moment talking about reusing some code from the past. In other words, all the interfaces and abstractions you are being ...


1

You should define a set of interfaces based on what you want your software to do, then build some adapter to fit in the libraries you want to use (aka build role interfaces). Avoid using the libraries "as is", or defining you interfaces matching the library you are using (avoid header interfaces). You may find interesting posts about this under the title: "...


0

The best way to use a third-party library in your code is to introduce an abstraction class/layer between your code and the third-party library. This has the advantage that you can make clear which functionality you use from the third-party library (you seldom use everything from a third-party library), and also that the classes and types of the third-party ...


7

Java interface design: where should I put a lot of duplicate code that will be used by all subclasses? First, this is not interface design. This is implementation detail. Nothing outside Tuple needs to know where you put your code. Second, be sure this duplicate code really should be lumped together. Sometimes code needs to be allowed to change ...


5

It depends, but the usual alternatives are make it a static member of a separate utility class make it a member of a separate class (you will have to instantiate an object of that class somewhere) put it into a common base class TupleBase which derives from Tuple, and let Tuple1, Tuple2 derive from TupleBase. And without providing more context and ...


3

Have a look a Java abstract classes and see if that works for your current use case. An AbstractTuple or BaseTuple or GenericTuple can "fill-in" the methods you wish to have shared between implementations and leave abstract methods to be defined by concrete classes. This should generate a compiler warning and should be pretty safe to use. When designing ...


Top 50 recent answers are included