• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

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?



  • 2
  • 2
  • 2
2 Solutions
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?

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).
corconAuthor Commented:
Thanks for your responses.
Now that I know the correct terms, I can search the internet more specific.

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.

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.

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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.
I would construct classes as follows.

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.

This abstract class contains behavior and members common to all actions

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

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.

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

This class represents pre-configured events.

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

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

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.

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

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

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,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now