Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere do I place common logic required in multiple classes implementing the same interface?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COLooks like there's a very similar question here: http://stackoverflow.com/questions/5343923/where-to-put-common-interface-methods-when-dealing-with-partial-classes-inherit - only saw it in the Related section after I posted this one! Although mine is when two methods do different things but have common logic embedded within them...
      singulars
    2. COIt's a bit unclear what specifically you're deeming common logic here. You're indicating a line of code that doesn't refer to the properties of the class at all so it could just be factored out into a static method in some utility class. If your common code uses the class members you may be able to use an extension method, but only if these members are exposed by the interface. Finally you could use a base class. But the 'right' answer depends somewhat on the specifics of the common logic.
      singulars
    3. CO@James: thanks for your comment. Sorry, my mistake: I made the common logic too simplistic but a and b are objects of two different types/classes which do not belong to the implementation classes. So, based on your comment, it should probably be placed in a static method in a utility class.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload