samedi 24 décembre 2016

Store and access data from reflection

I have a jar file, which is used by 2 different applications. In this jar file a have some models annotated with special annotation:

public interface Component {
   // title, image and other properties
   String getId();
}

@ComponentToParse
public class Component1 implements Component {
   //
}

@ComponentToParse
public class Component2 implements Component {
   //
}

In first application these models are listed into ComboBox and then id of selected component is copied to clipboard;

In second application i click paste and need to create this Component by id.

So, i need at least two classes:

  1. Class, which returns all components or return components by some category etc.(DAO, Repository etc)
  2. Class, which creates components by id.

My current solution is:

  1. ComponentsRepository (implementation of Repository, has getAll(), getByCategory() and others), it calls ComponentsFactory.createAll() when constructs.
  2. ComponentsFactory (implementation of Factory, has create(String id) and createAll which return list of all Components). In this class i use reflection methods.

But i think createAll in factory is very bad solution.

What is the correct way to do this?





Aucun commentaire:

Enregistrer un commentaire