Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

A Simple Simulation of Component Based Data Transfer and Processing

2.00/5 (2 votes)
6 Feb 2009CDDL2 min read 16.1K  
A class which simulates components which transfer data through inputs and outputs.

Introduction

As most people here on CodeProject will know, there are many Programming Paradigms, which, among other things, have different ways of dealing with data. Stuck with things to do one lunchtime, I decided to try my hand at simulating a component based method of data transfer (see http://en.wikipedia.org/wiki/Component-based_software_engineering). The way I've done it is most likely completely inefficient, but seeing as I couldn't find a way to group a number of different custom classes in a "Dictionary<>", I was stuck with this.

Background

In this approach, I've used a single class to simulate a number of different "gates". Each gate has a number of different inputs and outputs, and data which can be stored within the gate. For each "tick", the gate will take its inputs, and adjust its outputs accordingly. This is accomplished through a single "Gate" class, and a global output table. The Gate class has all of the functions for the gates within it.

Using the code

Gates can easily be added by adding the following piece of code to the "Gate" class.

C#
public enum GateTypes { YourGateName, <other gates> }
case GateTypes.YourGateName: < RegisterInput("InputName"); RegisterData("DataName); > 
case GateTypes.YourGateName: < SetOutput("outputname",GetInput("inputname")) > 
     // or some other function

Gates are then created using the following code in the "Engine" class:

C#
Gate MyGate = new Gate(GateTypes.YourGateName);

Outputs are connected to inputs using the following code:

C#
MyGate.Connect("inputname",SomeGate,"outputname");

Running the project will produce the output in the console. However, you need an output gate to print the output!

As I said...

This was something to do for a lunchtime. I wondered whether anybody would be interested, so I posted it here. If you have any way of storing multiple different classes in a dictionary, please don't hesitate to tell me!

There is probably a much more efficient/easy/user-friendly way to do what I did.

To-Do

  • Add more gates.
  • Add functions for existing gates which currently do nothing.
  • Allow connection of outputs to the same gate's inputs.

History

  • 06/02/09 - Created article.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)