It is currently 27 Apr 2024, 21:46
   
Text Size

[refactoring] merge Interface with Impl classes

Moderators: North, BetaSteward, noxx, jeffwadsworth, JayDi, TheElk801, LevelX, CCGHQ Admins

[refactoring] merge Interface with Impl classes

Postby North » 31 May 2014, 13:18

I know there are people who live and die by the interface segregation principle but I'm of the opinion that an abstract class works as good as an interface to define a contract, if not better. And it comes with the advantage that you don't need the extra redirection level nor the duplication.

I only use interfaces in two cases.
  • There are at least 2 immediate implementations in the abstraction tree and there is no instance behavior that would render an abstract class more suitable.
  • You want to restrict the API and define the interface so that you can pass object with as much methods as needed.
North
DEVELOPER
 
Posts: 93
Joined: 15 May 2011, 08:20
Has thanked: 8 times
Been thanked: 15 times

Re: [refactoring] merge Interface with Impl classes

Postby North » 31 May 2014, 16:44

I did this for the Watcher/WatcherImpl pair. It worked like a charm.

One more point in favor of this refactoring would be to have consistency in the codebase.
North
DEVELOPER
 
Posts: 93
Joined: 15 May 2011, 08:20
Has thanked: 8 times
Been thanked: 15 times

Re: [refactoring] merge Interface with Impl classes

Postby LevelX » 31 May 2014, 20:09

Generally no problem for me to remove interface classes if not needed.

And if it's very easy to remove so the interface could not be so neccessary for this class.
User avatar
LevelX
DEVELOPER
 
Posts: 1677
Joined: 08 Dec 2011, 15:08
Has thanked: 174 times
Been thanked: 374 times

Re: [refactoring] merge Interface with Impl classes

Postby North » 04 Jun 2014, 21:00

I have to admit that IntelliJ is awesome for navigating code and refactoring. It is very easy to inline the interfaces in the Impl classes. Before I go on to merge my changes, I created a branch where I already did this for all the Effect class hierarchy. Please take a look and let me know what you think.

If everything looks good, I'll go ahead and merge this changes and go on to the remaining interfaces with an Impl class implementation.

PS: Extracting an interface if needed is also simple. Since the interface defines getters and things like this, I believe we are better of just using the abstract classes for defining a contract.
North
DEVELOPER
 
Posts: 93
Joined: 15 May 2011, 08:20
Has thanked: 8 times
Been thanked: 15 times


Return to Developers Talk

Who is online

Users browsing this forum: No registered users and 11 guests


Who is online

In total there are 11 users online :: 0 registered, 0 hidden and 11 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 11 guests

Login Form