I have a a bunch of rows in a table which store some variables and associated values. I have to fire a task depending the values of the variables from different rows. Multiple values from multiple rows can be overlapped by AND/OR conditions. What design pattern will be helpful to reduce cyclomatic complexity in this situation?
Lets say, Table
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 50%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table>
<tr>
<th>var v1</th>
<th>var v2</th>
<th>var v3</th>
<th>var v4</th>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr>
<tr>
<td>e</td>
<td>f</td>
<td>h</td>
<td>i</td>
</tr>
<tr>
<td>j</td>
<td>k</td>
<td>l</td>
<td>m</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>e</td>
<td>f</td>
</tr>
<tr>
<td>b</td>
<td>c</td>
<td>c</td>
<td>d</td>
</tr>
<tr>
<td>e</td>
<td>f</td>
<td>c</td>
<td>d</td>
</tr>
</table>
Now at runtime some condition needed to be tested. For example,
if v1 column has any value 'a' or 'b' AND 3rd and 4th row contains any 'g' OR all of 5th row contains value 'f', etc.
This kind of requirements are dynamic under certain fixed boundary and I have to prepare a method which takes the input table, and conditions. The method finally returns true/false. If I implement naively I need many nested if/else under full bounded possible conditions which makes my code much complex. What will be good pattern to handle it.
Aucun commentaire:
Enregistrer un commentaire