formatting
Source Link
JimmyJames
  • 24k
  • 2
  • 47
  • 82

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

MeansFor example:

Description   | Value |
--------------|-------|
1             |     1 |
2             |     2 |
3             |     3 |

Means, the description (key of an enum) is bound to a value (stored in the enum).
  There are multiple (ui-elements) tables, where this approach fits the requirement in an optimal way. Values and description are (as said) stored in enums and read for creating the table (ui-element).

Now, I have to face the situation, that there should be more than one column (of an ui-element table) with values. E.g. For example:

|||
Description 1 | Value1 1 | Value2 1 |...
Description 2 | Value1 2 | Value2 1 |...
Description 3 | Value1 3 | Value2 1 |...

Description   | Value1 | Value2  |
--------------|--------|---------|------ 
1             |      1 |       1 |...
2             |      2 |       1 |...
3             |      3 |       1 |...

For the columns (of an ui-element table) applies that they are all similar. The only difference they have is there is an underlying SQL (or an sql string inside the enum) , where for each value for the specific column in the specific row is requested.
So

So let's say our table (ui-element) defines due to the row a specific animal and due to the column a specific location.
In the specific cell, there is the amount of animals in the zoo for the given animal and location.

  E.g.For example (database sight) Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'

--Value1 1 
SELECT * FROM ZOO WHERE [...] AND **LOCATION = 'CA'**

--Value2 1 
SELECT * FROM ZOO WHERE [...] AND **LOCATION = 'UA'**



  Data:

|CA|UA|
Turtle |.3..| 9 |...
Lions |.6..| 1 |...
Horse |4..| 0 |...

Description| CA | UA  |...
-----------|----|-----|----- 
Turtle     |.3..|  9  |...
Lions      |.6..|  1  |...
Horse      |4.. |  0  |...

One approach would be to create the same objects in the enum again with passing the location as additional parameter. This way would result in having:

Enum Values(

  • Value1 1_CA
  • Value2 1_UA
    )
Enum Values(
 - Value1 1_CA
 - Value2 1_UA
)

Another way I thougtthought of was refactoring the enum to an abstract class and derive from it, so that I have the base values and only objects/class like following

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

Means, the description (key of an enum) is bound to a value (stored in the enum).
  There are multiple (ui-elements) tables, where this approach fits the requirement in an optimal way. Values and description are (as said) stored in enums and read for creating the table (ui-element).

Now, I have to face the situation, that there should be more than one column (of an ui-element table) with values. E.g.:

|||
Description 1 | Value1 1 | Value2 1 |...
Description 2 | Value1 2 | Value2 1 |...
Description 3 | Value1 3 | Value2 1 |...

For the columns (of an ui-element table) applies that they are all similar. The only difference they have is there is an underlying SQL (or an sql string inside the enum) , where for each value for the specific column in the specific row is requested.
So let's say our table (ui-element) defines due to the row a specific animal and due to the column a specific location.
In the specific cell, there is the amount of animals in the zoo for the given animal and location.

  E.g. (database sight) Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'



 

|CA|UA|
Turtle |.3..| 9 |...
Lions |.6..| 1 |...
Horse |4..| 0 |...

One approach would be to create the same objects in the enum again with passing the location as additional parameter. This way would result in having:

Enum Values(

  • Value1 1_CA
  • Value2 1_UA
    )

Another way I thougt of was refactoring the enum to an abstract class and derive from it, so that I have the base values and only objects/class like following

For example:

Description   | Value |
--------------|-------|
1             |     1 |
2             |     2 |
3             |     3 |

Means, the description (key of an enum) is bound to a value (stored in the enum). There are multiple (ui-elements) tables, where this approach fits the requirement in an optimal way. Values and description are (as said) stored in enums and read for creating the table (ui-element).

Now, I have to face the situation, that there should be more than one column (of an ui-element table) with values. For example:

Description   | Value1 | Value2  |
--------------|--------|---------|------ 
1             |      1 |       1 |...
2             |      2 |       1 |...
3             |      3 |       1 |...

For the columns (of an ui-element table) applies that they are all similar. The only difference they have is there is an underlying SQL (or an sql string inside the enum) , where for each value for the specific column in the specific row is requested.

So let's say our table (ui-element) defines due to the row a specific animal and due to the column a specific location.
In the specific cell, there is the amount of animals in the zoo for the given animal and location. For example (database sight)

--Value1 1 
SELECT * FROM ZOO WHERE [...] AND **LOCATION = 'CA'**

--Value2 1 
SELECT * FROM ZOO WHERE [...] AND **LOCATION = 'UA'**

Data:

Description| CA | UA  |...
-----------|----|-----|----- 
Turtle     |.3..|  9  |...
Lions      |.6..|  1  |...
Horse      |4.. |  0  |...

One approach would be to create the same objects in the enum again with passing the location as additional parameter. This way would result in having:

Enum Values(
 - Value1 1_CA
 - Value2 1_UA
)

Another way I thought of was refactoring the enum to an abstract class and derive from it, so that I have the base values and only objects/class like following

added 1177 characters in body
Source Link
J-P
  • 37
  • 4

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables (ui-elements) with a key-value appearance.

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

There
Means, the description (key of an enum) is bound to a value (stored in the enum).
There are multiple (ui-elements) tables, where this approach fits the requirement in an optimal way. Values and description are (as said) stored in enums and read for creating the table (ui-element).

Now, I have to face the situation, that there should be more than one column (of an ui-element table) with values. E.g.:

For the columns (of an ui-element table) applies that they are all similar. The only difference they have is inthere is an underlying SQL (or an sql string inside the enum) , where thefor each value for the specific column in the specific row is requested.

E
So let's say our table (ui-element) defines due to the row a specific animal and due to the column a specific location.
In the specific cell, there is the amount of animals in the zoo for the given animal and location.

E.g. (database sight) Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'



|CA|UA|
Turtle |.3..| 9 |...
Lions |.6..| 1 |...
Horse |4..| 0 |...

This value (for location or the row) is/was constant in the enum and seems to be the breakpoint, breaking this hard-wired construct.

How could this problem be solved without breaking the concept of clean OOP?

PS: Has i have slept now one night above this problem, I think i'll use the enum as parameterclass, passing to a separate class (and thus it's constructor) to create the elements in a generic way (by giving the additonal parameter for each row (location)). Because the order is constant, i think this approach will help by solving it this way. If this is the way I can solve it, I will write it as separate problem solution in the comments.

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables with a key-value appearance.

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

There are multiple tables, where this approach fits the requirement in an optimal way. Values and description are stored in enums.

Now, I have to face the situation, that there should be more than one column with values. E.g.:

For the columns applies that they are all similar. The only difference they have is in an SQL, where the value is requested.

E.g. Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'

This value is/was constant in the enum and seems to be the breakpoint, breaking this hard-wired construct.

How could this problem be solved without breaking the concept of clean OOP?

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables (ui-elements) with a key-value appearance.

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

Means, the description (key of an enum) is bound to a value (stored in the enum).
There are multiple (ui-elements) tables, where this approach fits the requirement in an optimal way. Values and description are (as said) stored in enums and read for creating the table (ui-element).

Now, I have to face the situation, that there should be more than one column (of an ui-element table) with values. E.g.:

For the columns (of an ui-element table) applies that they are all similar. The only difference they have is there is an underlying SQL (or an sql string inside the enum) , where for each value for the specific column in the specific row is requested.
So let's say our table (ui-element) defines due to the row a specific animal and due to the column a specific location.
In the specific cell, there is the amount of animals in the zoo for the given animal and location.

E.g. (database sight) Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'



|CA|UA|
Turtle |.3..| 9 |...
Lions |.6..| 1 |...
Horse |4..| 0 |...

This value (for location or the row) is/was constant in the enum and seems to be the breakpoint, breaking this hard-wired construct.

How could this problem be solved without breaking the concept of clean OOP?

PS: Has i have slept now one night above this problem, I think i'll use the enum as parameterclass, passing to a separate class (and thus it's constructor) to create the elements in a generic way (by giving the additonal parameter for each row (location)). Because the order is constant, i think this approach will help by solving it this way. If this is the way I can solve it, I will write it as separate problem solution in the comments.

Source Link
J-P
  • 37
  • 4

Best pattern to solve problem where objects only differ in one attribute

As I am maintaining and extend a software system in Java, I saw a colleague (who left due to retirement) implementing a table with a generic approach. This approach is unluckily bound to tables with a key-value appearance.

E.g.
___|
Description 1 | Value 1
Description 2 | Value 2
Description 3 | Value 3

There are multiple tables, where this approach fits the requirement in an optimal way. Values and description are stored in enums.

Now, I have to face the situation, that there should be more than one column with values. E.g.:

|||
Description 1 | Value1 1 | Value2 1 |...
Description 2 | Value1 2 | Value2 1 |...
Description 3 | Value1 3 | Value2 1 |...

For the columns applies that they are all similar. The only difference they have is in an SQL, where the value is requested.

E.g. Value1 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'CA'

Value2 1 SELECT * FROM ZOO WHERE [...] AND LOCATION = 'UA'

This value is/was constant in the enum and seems to be the breakpoint, breaking this hard-wired construct.

One approach would be to create the same objects in the enum again with passing the location as additional parameter. This way would result in having:

Enum Values(

  • Value1 1_CA
  • Value2 1_UA
    )

Which seems to create a big overhead, since the objects only differ in location, but all other parameters are the same.

Another way I thougt of was refactoring the enum to an abstract class and derive from it, so that I have the base values and only objects/class like following

  • CA extends BaseClass
  • UA extends BaseClass

However this seems not like a clean approach, more like an "make it any case works" approach. Inheritance would be used in the way it shouldn't be, so I thought of delegation. But for delegation, the BaseClass must be instantiable (which is incorrect too).

How could this problem be solved without breaking the concept of clean OOP?