Is an empty implementation of abstract methods a good approach?

I work with two different Google Analytics services (Google Analytics and Mixpanel) for my Android application.

I created an abstract base class as follows:

public abstract class AnalyticsService {

    public abstract void trackAppOpen();
    public abstract void identifyUserOnLogin();

}

Then I created specific subclasses that were extended from the base class AnalyticsService.

public class MPAnalytics extends AnalyticsService {
    @Override
    public void trackAppOpen() {
        //Send event to MixPanel
    }
    @Override
    public void identifyUserOnLogin() {
        //Identify user with MixPanel
    }
}

public class GoogleAnalytics extends AnalyticsService {
    @Override
    public void trackAppOpen() {
        //Send event to Google
    }
    @Override
    public void identifyUserOnLogin() {
        //Do nothing
    }
}

Now Google Analytics does not actually support user authentication, so I had to create an empty method implementation registerUserOnLogin().

I believe this is probably the wrong way to do this, since user identification is not a behavior in Google Analytics, and therefore, ideally, it should not be part of the base class AnalyticsServiceand should be defined in the MPAnalyticsclass.

, , AnalyticsService .

List<AnalyticsService> analyticsServices;
for (AnalyticsService service : analyticsServices) {
    service.trackAppOpen();
    service.identifyUserOnLogin(); // where should this method be?
}

? .

+4
1

, .
→ , - .
,

+1

All Articles