Click here to Skip to main content
15,891,375 members
Articles / Programming Languages / C#

A Simple Simulation of Component Based Data Transfer and Processing

Rate me:
Please Sign up or sign in to vote.
2.00/5 (2 votes)
6 Feb 2009CDDL2 min read 15.8K   7   4
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)


Written By
Student
United Kingdom United Kingdom
I am a Student and a hobbyist programmer, programming mainly with C# and Python.

Comments and Discussions

 
GeneralMy vote of 1 Pin
S.H.Bouwhuis24-Mar-09 6:18
S.H.Bouwhuis24-Mar-09 6:18 
GeneralExamples Pin
Henry Minute6-Feb-09 8:12
Henry Minute6-Feb-09 8:12 
GeneralRe: Examples Pin
ABitSmart6-Feb-09 16:52
ABitSmart6-Feb-09 16:52 
AnswerRe: Examples Pin
Jonny2458-Feb-09 23:34
Jonny2458-Feb-09 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.