2

I'm writing an app which tracks device location and based on some factors (user gets an assignment), it needs to change the location tracking settings (for example, frequency).

I have an issue with how to design this.

// I left out methods to start\stop tracking
interface ILocationTracker
{
    event EventHandler LocationChanged(Position pos);

    void UpdateTrackingSettings(TrackingSettings settings);
}

interface IUser
{
    event EventHandler AssignmentAdded(Assignment a);
}

I don't want to couple the IUser to the ILocationTracker, so I added this (I'm leaving fields out so it looks simpler to read):

class UpdateLocationTrackingSettings
{ 
     public UpdateLocationTrackingSettings(ILocationTracker tracker, IUser user)
     {
     }

     // I need to somehow start/stop it listening to AssignmendAdded event
     public void Start() {
          // Subscribe to IUser:AssignmentAdded
     }

     public void Stop() {
          // Unsubscribe from IUser:AssignmentAdded
     }

      void OnAssignmentAdded(Assignment a)
      {
          TrackingSettings settings = GetSettingsByAssignment(a); 
          _tracker.UpdateTrackingSettings(settings);
      }
}

The questions I have:

  • How to 'start' the UpdateLocationTrackingSettings? Should I have a façade for the location tracking which contains ILocationTracking and UpdateLocationTrackingSettings and calls Start() on each?

  • I feel like for GetSettingsByAssignment I should use use strategy pattern. I am thinking to implement something like ITrackingSettingProvider which computes and returns the tracking settings based on the assignment.

  • Is this overthinking\over engineering?

  • Any suggestions of a different or better design?

2
  • 1
    Don't try and fit the problem to a "Design Pattern". Figure out the problem, and then see if a commonly-accepted pattern will solve it. Commented Jan 20, 2018 at 21:15
  • @MarkBenningfield I know that theory, I am not trying to find patterns just for the sake of it.
    – Daniel
    Commented Jan 21, 2018 at 7:49

1 Answer 1

2

Is this overthinking\over engineering?

YES. It's too early for you to make this choice. If you have a clear idea, then go with it. If you don't, then just write some tests and make them pass with the simplest possible code. If a circular class dependency arises, then break it by introducing an interface. When the code gets repetitive or ugly, then refactor. At that point some design pattern may fit your need.

6
  • Thanks, but you didn't mention which part I'm overthinking. I really don't want to couple the location tracker to the IUser. I already had a hunch I might be overthinking but I really don't want to couple things just for the sake of making it as simple as possible, I'd appreciate if you could share some feedback, thanks again
    – Daniel
    Commented Jan 20, 2018 at 20:27
  • 1
    @DonBox: Simple is KING. If the simplest and clearest way to accomplish the task is coupling, then couple away! Tell the buzzword police to jam a sock in it. Commented Jan 20, 2018 at 21:12
  • @MarkBenningfield You have my description of my task above. Why should I couple those two? It's as easy and simple not to.
    – Daniel
    Commented Jan 21, 2018 at 7:48
  • My app is more complex than my example, I have several other pieces where one of the piece needs to know about the other. If I'd start coupling everything just because its simple, the code starts to look like spaghetti.
    – Daniel
    Commented Jan 21, 2018 at 7:52
  • @Daniel: design patterns are common methods of refactoring working code. There's not enough code posted for us to make useful suggestions, or else you have reached most people's TL;DR limit. You might get more helpful answers if you posted a sample of working code to CodeReview. Commented Jan 21, 2018 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.