Greg
Greg

Reputation: 21

Class Names and Design patterns

Today I came across some weird case when thinking about naming my classes and using the right design-patterns.

I was curious how you solve this?

So the situation is:

I got some views in general like: View-1, View-2, View-3 Each view got attributes like: mode and readonly. Mode can be "edit" or "show" and readonly is a boolean. So for each View I had following example data:

View 1 - edit - true

View 1 - edit - false

View 1 - show - true

View 1 - show - false

Now I could assign a View to a WorkflowStep.. and this works fine right now. A WorkflowStep can have: buttons, views, actions and roles (in this case we just talk about the views).

The problem in this solution is.. that if I have more than one View, it gets a bit messy for the user, because he can choose from:

View 1 - edit - true

View 1 - edit - false

View 1 - show - true

View 1 - show - false

View 2 - edit - true

View 2 - edit - false

View 2 - show - true

View 2 - show - false

etc.

As I'm developing in Laravel I used Polymorphic relationship with a table called: workflowstepable. So I could assign a view to a workflow step, and the workflowstepable-table looked like:

workflow_step_id| workflowstepable_id| workflowstepable_type

  1            |        1           |   App\View

As this was a solution that has grown with the project.. i thought about a redesign. Right now the User has to choose from 8 views to drag and drop into a workflowstep. I would like to only show 2 views (View1, View2) to the User.. now he can drag and drop the view into a workflowstep.. and add further information like mode and readonly to only this specific ViewItem dropped into the Workflowstep.

I thought it would be better to split into following classes:

View: id, name, description

ViewItem: id, view_id, workflowstep_id, mode, readonly

WorkflowStep: id, order, etc.

So View would hold Views in general, like View1, View2 .. and ViewItem would bind the View to the WorkflowStep (1:1) and hold some more information like: mode, readonly.

Would ViewItem be a good name?

I would like to know if this is a common pattern, or if I'm missing something.

Upvotes: 0

Views: 100

Answers (1)

Pradeep Kumar
Pradeep Kumar

Reputation: 1491

Class name should be reflect the behavior or meaning of class so as per my understanding, it can be ViewAttributes/ViewProperties because your class is defining attribute of view like edit or show.

I think Builder Design Pattern can work there and by this pattern, Can give different representation to each view in future.

Upvotes: 1

Related Questions