Question

I'm trying to restructure some specific GUI code in a Java project, let's call it Project A, by removing dependencies from the project and moving the code to an existing API. I have another project which requires basically the same features/interface, and I'd like to reuse these capabilities in that other project.

I have read about the Facade Design Pattern in the Design Patterns book by the GoF, and thought that it may be applicable here.

Before reading about the Facade pattern, I attempted to write an interface called IMessagePasser, which simply replaces any project specific code with interface methods, as a contract to be implemented by each client, for example with ProjectAMessagePasser. This seems to deal with half of the Facade, allowing the GUI code to be moved to the API.

I suppose the next step is to do the same with the Project A, replacing the GUI dependencies by adding more methods inside the ProjectAMessagePasser, in order to figure out basically the necessary communications between the ProjectBMessagePasser and the GUI code.

I don't have a lot of experience with large scale restructuring of code, but does this all seem reasonable? It is hard to tell without making all the changes first, and I don't want to waste a lot of time doing it one way if there is a better way to do this.

Was it helpful?

Solution

To make it more manageable, you might want to create services for functional areas of the app, and focus your refactoring there. As you go, write unit tests to validate functionality. Once you have the functionality in services, you can create a Facade around those services.

in other words, it might be easier to divide and conquer, as opposed to refactoring the entire app at once.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top