Click here to Skip to main content
Licence CDDL
First Posted 6 Feb 2009
Views 8,130
Bookmarked 6 times

A Simple Simulation of Component Based Data Transfer and Processing

By | 6 Feb 2009 | Article
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.

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:

Gate MyGate = new Gate(GateTypes.YourGateName);

Outputs are connected to inputs using the following code:

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)

About the Author

Jonny245

Student

United Kingdom United Kingdom

Member

I am a Student and a hobbyist programmer, programming mainly with C# and Python.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberS.H.Bouwhuis6:18 24 Mar '09  
GeneralExamples PinmemberHenry Minute8:12 6 Feb '09  
GeneralRe: Examples PinmemberABitSmart16:52 6 Feb '09  
AnswerRe: Examples PinmemberJonny24523:34 8 Feb '09  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 6 Feb 2009
Article Copyright 2009 by Jonny245
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid