Porovnávané verzie

Kľúč

  • Tento riadok sa pridal
  • Riadok je odstránený.
  • Formátovanie sa zmenilo.

Jednotlivé moduly sú vzájomne prepojené s využitím návrhového vzoru Individual modules are interconnected using the Dependency Injection. Využíva sa na to knižnica design pattern. The Google Guice . Praktickým dôsledkom je, že je jednoduchšie vytvoriť samostatné testy jednotlivých modulov, ktoré sú zasadené do testovacieho prostredia.
Knižnica Google Guice má veľmi dobrú dokumentáciu, preto tu spomenieme len nutné minimum.library is used for this. The practical consequence is that it is easier to create separate tests of individual modules that are embedded in the test environment.
The Google Guice library has very good documentation, so we will only mention the necessary minimum here.

  • Instances of objects (only large objects that represent individual modules) are created by the Injector by calling .getInstance(Class<T>). The call parameter specifies the type of the new instance and should be an interface so that different implementations of this type can be cast in different circumstances
  • The Injector follows the configuration defined by the AbstractModule object. A specific implementation of a "module" with
  • Inštancie objektov (len veľkých objektov, ktoré reprezentujú jednotlivé moduly) vytvára Injector volaním .getInstance(Class<T>). Parameter volania určuje typ novej inštancie a mal by to byť interface, aby bolo možné za rôznych okolností dosadiť rôzne implementácie tohto typu.
  • Injector sa riadi konfiguráciou, ktorú definuje objekt typu AbstractModule. Konkrétna implementácia „modulu" volaniami .bind(Class<T>).to(Class<? extends T>) definuje konkrétne triedy, ktoré implementujú požadované rozhrania. Napríklad calls defines specific classes that implement the required interfaces. For example:

.bind(Main.class).to(MainImpl.class)
V prípade, že na vytvorenie inštancie má byť použitý špecifický postup, modul môže tento postup implementovať metódou označenou anotáciou @Provides.If a specific procedure is to be used to create an instance, the module can implement that procedure with a method annotated with the @Provides annotation.

  • The implementing class must have a public standard constructor or a constructor marked with the @Inject annotation, whose parameters are all interfaces for which the module defines assignments. The Injector then supplies the individual instances as arguments.
  • The Injector can also resolve circular dependencies by creating a placeholder object
  • Implementujúca trieda musí mať verejný štandardný konštruktor, alebo konštruktor označený anotáciou @Inject, ktorého parametre sú všetko rozhrania, pre ktoré modul definuje priradenia. Injector potom dodá jednotlivé inštancie ako argumenty.
  • Injector dokáže vyriešiť aj kruhové závislosti a to tým, že vytvorí zástupný objekt.