goGPS-Project/goGPS_Java

A truly modular design (refactoring ReceiverPosition)

Closed this issue · 6 comments

I don't know about goGPS Matlab but in the Java version there's a lot of copy&paste.
It's true that the design of goGPS is modular but that is not reflected in the code: each module basically copies and extends another one.
That makes it very easy to read, but harder to maintain because when something changes, all those copies have to change too.
Perhaps we could create a branch called "modular redesign" and experiment there, what do you guys think?

I agree with you, we need to remove or at least reduce the redundant code.
Please go on with the branch!

2015-10-26 22:20 GMT+01:00 Emanuele Ziglioli notifications@github.com:

I don't know about goGPS Matlab but in the Java version there's a lot of
copy&paste.
It's true that the design of goGPS is modular but that is not reflected in
the code: each module basically copies and extends another one.
That makes it very easy to read, but harder to maintain because when
something changes, all those copies have to change too.
Perhaps we could create a branch called "modular redesign" and experiment
there, what do you guys think?


Reply to this email directly or view it on GitHub
#17.

Some thoughts, after using Java 8 for the past month, I got to love lambdas and related APIs such as Function and Supplier.

I can see ReceiverPosition evolving into a functional type of class, where we can pass functionality that can be composed. Even with old Java 7, we could change the API to be:

ReceiverPosition( CodeFunction )
ReceiverPosition( CodeFunction, PhaseFunction )
ReceiverPosition( CodeFunction, KalmanFilterFunction )
ReceiverPosition( CodeFunction, PhaseFunction , KalmanFilterFunction )
...

with each "supplier" providing the ability to add rows and columns to the matrix A, for example they could implement an interface:
Matrix mtxSupplier( Matrix A)

Not sure yet whether they should operate on the whole matrix or on either rows or columns or both.

I've started some refactoring work.
First steps:

  1. Move ReceiverPosition to a new package (core, or positioning if you prefer)
  2. Start splitting the individual algorithms into separate classes. I'll try to follow the Matlab version naming conventions but I don't know that code very well, so please feel free to provide any suggestion

This change will affect the "troposphere" branch but it should be reasonably easy to merge changes from that branch manually

Here we go: dce1a9e

Ok, I've broken it! by refactoring the "state" (like SatellitePosition[] pos) out of ReceiverPosition, I've now got a duplication of that state that is currently not shared.
So if we call first selectSatellitesStandalone(), then new LS_SA_code(goGPS).codeStandalone(), the SatellitePosition array is inside the first object, not the second. So please bear with me, and don't use it yet, because it doesn't work :-/

All done -> 843f5ad

Tested by y running TestGoGPS.main() in different modes