Hello, say you are implementing an api that usually takes data in the form of associative arrays, processes them for validation etc and converts them into a different format (still an array, although the keys and overall structure is different), and then sends them off to get processed further. What would be the best way to handle this.
Essentially my main objectives are:
- Receieve associative arrays in arbitrary structures for different objects i.e. product, consumer, staff.
- Validate that each element in the array is in the correct format and length etc. i.e. consumer first name is a string, their age is a date etc.
- Convert the recieved associative arrays that have just been validated, into the correct format that the next stage is expecting. i.e. they need to work with the same data but in a different structure - this is proving particularly difficult without hard coding each structure both incomming and outgoing.
- Pass the validated data on for storage (i am only concerned with passing the data on and not what happens with it then)
- Keep track of all errors and success that occur and report those back(in batch)
I am thinking of having a class that simply has the main functions i.e. addConsumer(), addStaffMember() and keep this really simply, like the facade pattern.
Then I may have a ConsumerManager class which takes care of all the functions for a consumer and the same for the staff etc.
Beyond that, i am starting to struggle with a good overall design that will require very little change in adding new functionality or updating existing functionality.
Are there any obvious patterns that jump out from this?