ericcornelissen / NervousFish

An app for your :iphone: to exchange public-keys in a secure manner.
GNU Lesser General Public License v3.0
2 stars 4 forks source link

Structure #41

Closed jverbraeken closed 7 years ago

jverbraeken commented 7 years ago

What

This PR add the main structure to the project.

Why

This is done so that all developers can start coding against an interface that provides a rough direction and to make sure that the project is extensible, safe and fast.

How

3 things are central: encapsulation (everything private), immutability (every final) and extensibility (everything what could be extended in the future coded against an interface). All functionality is placed in modules to have the project modular. To give classes access to these modules they can a certain class, namely a Service Locator, for any of these modules. Singletons are bad, so therefore the Service Locator is dependency-injected (so passed as a parameter) to new classes that may need the service locator. To get the highest degree of encapsulation possible, the service locator constructor is (package-)private. To construct a new ServiceLocator the client can use a new ServiceLocatorCreator. His constructor is also (package-)private so this class can only be made by MainActivity (the only "system" Activity). All modules have private constructors as well and the service locator can request modules by asking the class to wrap a new instance of the class in a ModuleWrapper. The reason that this is done is to make sure that all variables are final (even the circular dependency between the service locator and every module) and to make sure that all modules of a service locator are initialized. A few class names are pretty long, but that's ok because the client will only use the interface, the class itself is irrelevant is only used once in the ServiceLocatorCreator.

Notes

I opened this PR without running any of the code quality tools because they do not work for me yet and this pr is needed. So running the code quality tools while reviewing is appreciated.

jverbraeken commented 7 years ago

@ericcornelissen I've implemented all your suggestions!