mardi 29 septembre 2015

Java extending - best refactoring pattern

I know that I broke open-close principe, but previous architecture does not require such functionality. That's a story:

I have one abstract activity that extends CordovaActivity(from XWalk library), and have two concrete activities that extend it - both with its own scope of logic, a lot of that logic has calls to protected methods of activity class. And now we have problems with crosswalk on some custom emulators, I haven't even access to them. The most problem is CordovaActvities from XWalk and from cordova have almost the same api, but without any general interface, so code for both abstract activities will be almost the same, but parent class should be different. So, is there some elegant way to do this without blind copy-paste, but without core refactoring of my classes?

I was thinking about some kind of dependency injection for my business logic resolver using empty fragments - they allow me to use most of activity-related methods. Or move most generic UI features also to fragments.

But I believe that there should be some easier way just to change parent classes and few methods signatures?

ConcreteLogicActivity1 extends BaseActivity
ConcreteLogicActivity2 extends BaseActivity

BaseActivity extends XWalkActivity

Now I need to make

XWalkBaseActivity extends XWalkActivity
CordovaBaseActivity extends CordovaActivity

then I'll have Logic1 derived from XWalk and Cordova, and Logic2 too. But it will be primitive copy-paste with a lot of the same code.

Aucun commentaire:

Enregistrer un commentaire