When not to implement a common interface?

Is there a general rule when you should and should not have a common interface?

My example is a simple data frame interface. There is a member of "user data" that allows you to embed any data related to a specific implementation that needs to be executed with the frame. I don’t know whether to leave it as an object type (and require it from it), or to have a common interface for this single member, so the compiler will work poorly.

If it becomes common, then the line of use must also be common in order to get the type passed along the string (if that makes sense). It seems to me that this is a lot of work for this one member, which underlies my question.

Thank!

+3
source share
2 answers

One area where generics tend to break is heterogeneous collections. If your data frame objects are combined into one type of collection to be transferred, it may be difficult for you to use generics. In particular, since in the example you provide, there is no base type that inherits all the "user data" except the object.

In fact, in these types of problems you can define both a common interface and a non-universal version so that you can pass types polymorphically.

Generics are powerful and very useful, but in the example you are describing, I suspect that they may be more of a problem than they are worth it.

+3
source

Issues to consider when deciding:

  • ? (, / string, int?)

  • ? ?

  • , , ?

+3

Source: https://habr.com/ru/post/1726667/


All Articles