Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I and a friend are having an argument on what is the better technique to use in

ID: 645812 • Letter: I

Question

I and a friend are having an argument on what is the better technique to use in the following scenario:

An application we need to test has a number of components (lets call them Eggs); each component is a bag of predefined sub-components. These components are the input to our application, there is no way we can change/annotate these components at their source.

Now, we have a set of validators for each sub-component. It is not programatically possible to associate an Egg with its validators, so it has to be done manually for each new Egg (there are a finite number of eggs). Once the mapping is done, we can run each validator for each Egg to see if the Egg is good or rotten.

Now, my way of doing it is to have a config file which consists of the mapping between each Egg and its validators. Eg:

{
Egg1: [validator1, validator2]
Egg2: [validator5, validator7, validator2]
}
Now we can read this file and use reflections to select the appropriate validator (from the list of all classes implementing IValidator) for each Egg.

My friend is averse to using reflections, and prefers to add a new C# class for each Egg everytime a new type of Egg is added. The class represents the Egg and runs the appropriate validators for that Egg.

Which way is better? I prefer the reflections method because everytime a new type of Egg shows up all we need to do is edit the config.

To clarify, an Egg is a selection from predefined list of sub-components. Assume that there will be no more sub-components, and hence there is no need for new validators. We cannot enumerate all possible Eggs because there are too many.

Explanation / Answer

Which way is better?

Based on what you've described, adding a new class is way better.

why?

Because editing a config is just as hard/painful as editing code, except it's tons more error prone and requires more work to setup - and nobody coming into your company knows what the hell this config is, or what format it's in, or where to find it.

Now, if you could use reflection to inspect the Eggs and see what sub-components they have (and you don't have significant performance requirements), that seems like an even better solution...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote