1

I have the following requirements:

  1. Load data from a variety of sources and fill a list with it
  2. Use a batch of data to perform some computation

Some additional information:

  1. The algorithm for computation expects the list of data to be ordered by a key that comes with the data.
  2. I want to use a queue instead of a list inside the algorithm for performance reasons (Loaded data is already stored sorted)
  3. The data batch needs to be loaded beforehand

I tried to break the requirements up into different classes and came up with this design (pseudocode):

class Data {
    int key;
    // some more data fields
}

class SortedDataQueue{
    Data peek();
    Data dequeue();
    void enqueue(Data);
}

class ComputesData {
    Result performComputation();
    void setDataBatch(SortedDataQueue dataBatch);
}

class DataLoader {
    static SortedDataQueue loadFromJsonFile(File file);
    static SortedDataQueue loadFromDB(DataDAO dao);
}

Is this a good design?

I try to get better at software architecture/design, but it is really hard without someone experienced to review your work. I tried to follow the SOLID principles in this one.

1 Answer 1

1

I think you've done a great job in decoupling the dependencies, what I could suggest here is to not return already SortedDataQueue object from DataLoader since it's responsibility is only to retrieve data. In that case, you can create the class:

    class DataCollector {
        SortedDataQueue collectIntoQueue();
        DataCollector init(Array<Data> dataArray);
    }

And DataCollector's responsobility is to collect your batch of data into queue.

1
  • I thought the same when i refined my implementation yesterday. I will probably return an Array<Data> from my DataLoader and use a SortedDataQueue in my ComputesData class. If i ever get into a situation where i get unsorted data i can then quite easily implement a class that sorts the Array and returns a SortedDataQueue that i can work with. Jun 23, 2016 at 12:36

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.