How do you deal with exceptional cases

This is often the case, but here's a final example:

Companies have different contact details (addresses, phone numbers, emails ...), when they advertise a job, they have checkboxes where they choose how to contact them. This is mostly descriptive data. The user, when reading the ad, sees something like "You can apply by mail, in person ...", except when it is "through the web portal" or "by email", because then the corresponding buttons should appear. These parameters are stored in the database, and the client (the site owner, not the company creating the ad) can change them (for example, they can add "telepathy" or something else), but if they interfere with the "email" and "website" -portal ", they spin up their website.

So how should I handle the data, where everything behaves the same, except for "this thing" which behaves like this, and "this thing" which behaves differently, and the data itself is live, must be editable by the client ...

+1


source to share


5 answers


You marked your question as "language agnostic" and not all languages ​​fully support polymorphism, but the way I would do it.

Each option has a different type, and different types require different properties. However, each type supports some sort of "render" method that can render the contact method as needed. Since the properties (phone number or web address, etc.) are type dependent, you can check the administrator input when creating these "objects" to ensure that the required data is provided and valid. Since you are implementing a render method, instead of spitting out the HTML provided by the user, you can ensure that the page being rendered is correct. It is less flexible, but more secure and user-friendly.



In a database, you can have one sparsely populated table that contains data for all types of contacts, or a "parent" table with common properties and sub-tables with properties of the type. It depends on how many types you have and how different they are. In any case, you will have some kind of type indicator so that you know the type of object to which the data should bind.

+1


source


First of all, think twice about what you really need. The reason is simple. You have to serve a specific need, and the input is the vehicle for providing that service. If the data does not match the existing service, what is its value and who is the consumer of this particular information?



There are two possible answers: you are expanding your customer base or you need to change an existing service due to changing demand. In both cases, you need to think about developing a business model. If you describe what service you need and what information it should provide, you will avoid a lot of specific data and get clear requirements that are easy to implement in software.

+1


source


I would recommend a permission pattern for this based on the database mention. The link above describes it, but it's actually much easier than it sounds. You are writing a database query that returns all possible parameters (for example, you read standard parameters and custom parameters together, using perhaps UNION or JOIN depending on your schema). The COALESCE SQL keyword is useful for finding the first 'resolution' parameter value that is not NULL.

+1


source


Well, if all of this is the case, you have two special parameters and then everything else is treated the same, and then store your parameters as strings, and if one of the two specials appears in that list, then show the appropriate materials for that special item.

Just check your item list for two specials. Nothing unusual.

0


source


By writing a very simple rule engine . You can use a realistic implementation, or you can use it yourself. Since your case seems so simple, I tend to roll my own because it means less dependencies (YMMV).

0


source







All Articles