Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for configurable system

I have an interesting design problem that I will attempt to simplify in a toy problem below:

I wish to design a system for which the output will be student objects based on certain inputs and intermediary processing. The flow will be as follows: I have a list of classrooms as one type of input. To generate the output, the processing steps are:

  1. Filter each classroom by students under the age of X (lets say 10)
  2. Sort the filtered results by any permutation of this hierarchical order: height, weight, arm length
  3. Return the top 8 students.

Another input can simply be a list of students I already have and want included as part of the result. For example: Input 1: List of 3 students, Input 2: List of 2 classrooms for which the processing steps above will run.

What would be the best way to design such a system with inputs being:

  • input type {student list|classroom list},
  • filter type {age|height|etc},
  • sort order{any ordering of height,weight,arm length},
  • returnNum{how many students to return}

The system should be flexible enough to accommodate more input types and more sort order entries {ie. sort students by shoe size}. What data structure can I use to model each part of this section (ie. what is the best way to represent the sort order criteria?) Is there any design pattern that would fit these needs? Any help with the architecture design would be greatly appreciated!

like image 948
John Baum Avatar asked Oct 25 '15 18:10

John Baum


People also ask

What is configuration pattern?

It is sometimes useful to permit the end-user to modify certain characteristics of a pattern, such as whether to enable features that might be costly, or to change a set of default paths or package names. This is enabled with pattern configuration blocks. Pattern configuration is new in TPL 1.2.

What is design pattern with example?

Design patterns provide a standard terminology and are specific to particular scenario. For example, a singleton design pattern signifies use of single object so all developers familiar with single design pattern will make use of single object and they can tell each other that program is following a singleton pattern.


1 Answers

Well, what you're suggesting can be done easily with Java 8 streams, so I guess one pattern you could follow is that of a pipeline. You could also implement this using internal iterators:

List<Student> found = Stream.of(student1, student2, student3, ..., studentn)
    .filter(s -> s.getAge() > 100)
    .sorted(Comparator.comparing(Student::getHeight).thenComparing(Student::getWeight))
    .limit(10)
    .collect(Collectors.toList());
like image 85
Edwin Dalorzo Avatar answered Sep 21 '22 05:09

Edwin Dalorzo