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:
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:
{student list|classroom list}
, {age|height|etc}
, {any ordering of height,weight,arm length}
, {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!
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.
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.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With