How to repurpose code in two similar projects

Asked

Viewed 241 times

6

It concludes one project and I need to do another with the same context. The problem is that I know I will find bugs and I will evolve the code when I am developing the second. How do I make a way that I can fix a bug in both projects at the same time without having to open one by one and without having to lose the particularities that each one has.

2 answers

5


Configure your Build Path to use sources that are not within your project.

Click on Link Source... and indicate the path.

inserir a descrição da imagem aqui

Do this in your two projects, so you’ll have a unique base, so every time you change the source code to one you’ll be changing the source code of the other one as well. But you will have to make sure that each one’s interface is tracking the improvement of your base code.

  • The idea is good, but if I have the following problem: I have a News List in both projects, but one needs only 1 image for each listview item, the other needs two.

  • @Othon did not understand your example very well, but it is important that you separate your interface (graphical part) from the main logic of your program. So you can treat the peculiarities of each project in the class dealing with the graphical part.

  • So I would take the model and create a library of it?

  • @Othon What is the model? You don’t need to create a library, what I recommend is to take the base classes (.java) and put them separately from the two projects, hence in both projects you add the base classes in your build path. In the folder src of each project you will only have classes that are specific to that project, such as Activity’s class.

  • Ok. Model View Control are the layers that make up the MVC pattern. This is where the idea of separating logic(model) from visual(view) comes from. The control is responsible for communication between the two layers as well as some kind of verification of past information (such as a date wrongly). Your answer gave me a light on what to do

1

just take what is common to both and turn into a library, and then use the reference in both

  • 1

    Boa Tarde Paulo,

  • We were thinking about it, but we already have a complete project and it would be a lot of work to try to take the unusual part. Wouldn’t there be another way? It is very difficult to identify what I can reuse in other projects

  • Elegantly and that I know no.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.