Design Pattern

Hi everybody,

I'm working on a C# project that consists out of different campaigns where certain actions are triggered by events. In general this has a tree-like structure. But the difference is that some events can trigger the same action and events can trigger actions that are on a higher level. (Check out the added image for a clearer view of the situation).

I am now trying to create a Class structure and a DB-structure based on that. But that's where I 'm stuck  now. I created a structure based upon the treeview-stucture but that has some limitations on what we try to accomplish here.

I tried to search the internet and this site but I couldn't find a sollutin for this.

Can anyone help me with this or give me something that I can start with?

Thanks,

Nick.

Program-Structure.PNG
corconAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JimBrandleyCommented:
The structure of a Campaign from your illustration really is not a tree. It is a directed graph that:
A -  Can be convergent - multiple paths lead to a node from an ancestor, and
B - Can be cyclic - a single path can lead to the same node more than once.

In the graph, actions correspond to nodes, and events correspond to edges.

I would need a bit of clarification to propose a rough database structure.

1. Are the "Actions" labeled "Start" and "End" special initialization and cleanup actions, or are they something altogether different?

2. Is the first event (coming from start) a tru event, or is it just a link to the first true action?

3. Are the terminal events (leading to the "End") true events?

Jim
 
0
peprCommented:
To add tho JimBradley comments, the picture as presented describes a system that can work in parallel. Is the Action just above the End block to be activated by any of the 3 events or is it activated only when all 3 events are collected?

The problem with solving parallel problem in a sequential environment (i.e. single processor) is that the events must be serialized somehow. Think about a window GUI of an application -- events must be queued in a message queue.

In simulation system,  the structure named time calendar or time queue is used for planning activation to the "real" simulated time. When simulating fast parallel things (like semiconductor elements and systems) the steps of the time may be synchronized by the central clock -- i.e. the subsystems that perform the actions take the value on inputs in the time of the edge of the time pulse and compute the result to be used on the other inputs during the next time.

If the image is captured in a database (i.e. the dependency between the nodes is not fixed) then you should learn something about simulation systems (http://en.wikipedia.org/wiki/Computer_simulation). You should probably focus on Discrete event simulation (http://en.wikipedia.org/wiki/Discrete_event_simulation).
0
corconAuthor Commented:
Thanks for your responses.
Now that I know the correct terms, I can search the internet more specific.

@JimBrandley:
To answer your questions:
1. Are the "Actions" labeled "Start" and "End" special initialization and cleanup actions, or are they something altogether different?
          ==> The "Start" and "End" actions are indeed special initialization and cleanup actions.

2. Is the first event (coming from start) a true event, or is it just a link to the first true action?
          ==> Yes, the first event (coming from start) is a true event. In our case it will be a timed event (action will be processed on (date) at (time).
The other events can be both timed events or events that derive from the actions that are performed.

3. Are the terminal events (leading to the "End") true events?
          ==> The terminal events are true events.

      
@pepr:
The system should not be working in parallel. Only 1 path should be followed. If multiple events are triggered, the most important one is selected and that one is followed.
The links that you gave me in your post are very useful for when we are programming. But right now we are still on the point of designing our system.
The structure of actions and events will be saved in a database and right now I'm trying to find a good class structure to represent this kind of data.

Thanks.
Nick.
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

peprCommented:
I would probably think about your Actions as about objects that model some subsystem and when receiving some event do come computation (i.e. action) and generate the next event. Events should probably be represented also as objects. However, life-time and purpose of the two mentioned kinds of objects is different. The "Actions" should probably be renamed when designing to express better that they are models of subsystems that form the whole system.

Subsystem and event objects could be simple but also very complex. Anyway, the events should be passed to and generated by the subsystems. This way events should use common base class (probably the abstract one) that represents inevitable properties of any event. The subsystems should also share the same base class.

As the structure of the system is to be captured "outside" them, there should be other subsystem that is not related to the core of the solved problem (not part of the model). It should read your database, create the instances and capture their interconnection, redirect the events (mediator) and ensure the serialization of the events. The Start and End block could be parts of that control/simulation-core system.

The database should reflect the base classes of the subsystems (actions). It should capture some identification (used when interconnection of subsystems is described), kind of subsystems (class that models it), and initialization data if necessary. The simulator should pass the information to the "class factory" responsible for creating the objects.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JimBrandleyCommented:
I would construct classes as follows.

Context
This object contains state information and singleton object instances required by your business objects. For example:
   Current user identification
   Reference to your database access class
   Reference to a cache object if needed
   Reference to a logging object if needed
   Reference to a transaction controller if needed

I would create only a single instance of this object per application (or HTTP request if web-based). Create it in the program initialization or early in the page life cycle. Then pass it into the constructors of your other objects.

ActionBase
This abstract class contains behavior and members common to all actions

ActionDefinition
This class represents pre-configured actions. It owns a list of event definitions.

Action
This class represents instances of actions created from action definitions when a campaign is created from a campaign template. It includes state data, action behavior and decision behavior to determine which subsequent events are fired and when they fire. It owns a list of events.

EventBase
This abstract class contains behavior and members common to all events.

EventDefinition
This class represents pre-configured events.

Event
This class represents instances of events created from CampaignTemplates when a Campaign is instantiated.

CampaignBase
This abstract class contains behavior and members common to all campaigns.

CampaignTemplate
This class represents campaign configurations in your database. It includes attributes as needed, and a link to the initial Action. It owns lists of references to ActionDefinitions and EventDefinitions.

Campaign
Thais class represents instances of Campaigns created from CampaignTemplates. It includes state data and other attributes as needed, and lists of Actions and Events.


Database tables would reflect the objects they store. The assignment tables need to be designed to support the way you want to load them. For example, you might want to load an entire campaign for historical review of the activity, or you might not. If you have a need to load the entire campaign, the tables that relate events to actions need to include the campaign key so you can get them all with a single select. You would want to include the campaign key in the action table, both for loads and foreign key constraints.

Assigning actions to events could be handled by something like:
CREATE TABLE action_event
(
   Campaign_key,
   Parent_action_key,
   Event_key,
   Child_action_key
)

This is a start. If I have made some erroneous assumptions, let me know, and I can refine it.

Jim
0
corconAuthor Commented:
Hey Pepr and JimBrandley,

Thanks for your help.
I think I can continue from here.
I gave you both half the points.

Thanks again,
Nick
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Theory

From novice to tech pro — start learning today.