473,508 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design Question

9 New Member
Okay so I've got a delegate called "InstructionRun" (just a simple void with no parameters), and a class called "Instruction" which contains a delegate InstructionRun object as a member variable, as well as a method called "Run" which just calls the InstructionRun object's current functionality. There is also a byte in this class called "code".

Another class ("Instructions") has a static array of Instruction objects. It also has a static method whose purpose is to initialize all the Instruction objects.

And then somewhere else are a bunch of static void() methods that will be stored into the "InstructionRun" object for each Instruction object in the array.

My predicament is that I would like something like a simple text file or database to provide me with the data for this Instruction array. I want it to have a bunch of pairs, my "code" byte and then my static void() method. However, I would not want to resort to any of the following:

1) Not using a data file and just putting hundreds of "new Instruction()" lines to fill the array. I hate mass blocks like that when the design could change and then I have to change hundreds of those lines. I want something like a simple text file to just match up "code"s with functionality.
2) Putting the method's actual name in the data file, and then using reflection to read it during runtime and match it up with a method. Just seems sluggish and icky.

Please help out! If I wasn't clear on something, I can explain more.
Jun 8 '09 #1
8 1613
tlhintoq
3,525 Recognized Expert Specialist
I'm guessing the end goal is to change the order of start-up events by changing the config.txt file. But ...
[not] Putting the method's actual name in the data file
yet
Not using a data file and just putting hundreds of "new Instruction()" lines to fill the array. I hate mass blocks like that when the design could change and then I have to change hundreds of those lines.
Implies that you do have hundreds of methods, that all match the same delegate.

So, what... You're trying to create a text like


27, add
19, remove
89, load

Something like that?

That will eventually become a sequence that effectively does

Add(LoadedByte); // LoadedByte being 27
Remove(LoadedByte); // LoadedByte being 19
Load(LoadedByte); // 89 LoadedByte being 89

Do I interpret the goal correctly?
Jun 8 '09 #2
walentys
9 New Member
You are pretty much correct. I will have hundreds of methods, which is why I chose a delegate system as I don't want this:

Expand|Select|Wrap|Line Numbers
  1. switch (code)
  2. {
  3.    case 0x28:
  4.     RunADD();
  5.     break;
  6.    case 0x2A:
  7.     RunJMP();
  8.     break;
  9.    //so on...
  10. }
However, they are parameterless methods...they don't take a byte (actually I haven't decided that yet, they MIGHT have parameters down the line, but that's not important right now, right now I just need some way to match up the bytes with methods), but rather the byte determines which method to call.

So yes, my text would be something like:

28 RunADD
2A RunJMP
...
etc.

and then there would just be:

static void RunADD()
static void RunJMP()
...
etc.
Jun 9 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
Got it. Looks like you are making an assembly language simulator/translator.

Why not just make the methods match the bytes then? If you have a byte of 2A then run static void 2A(), which is the JMP instruction? Why do the lookup table at all?
Jun 9 '09 #4
walentys
9 New Member
That would be fine, I don't care what the methods are named....but even then, how would I go about matching up that byte coming in to that function named "2A"? Do I have to resort to reflection?
Jun 9 '09 #5
tlhintoq
3,525 Recognized Expert Specialist
Do I have to resort to reflection?
You say that like it's a bad thing. What are you trying to avoid about reflection, or what is it that makes your project hard to deal with reflection?
Jun 9 '09 #6
walentys
9 New Member
Nothing in particular, wouldn't it just slow it down? It seems a little excessive...getting a method name from a file, passing the string to look up a symbol name of the very program you're running in currently...when all you really need to do (though it might be uglier) is just call the damn method in the program. I was merely trying to look for a non-ugly way, maybe, avoiding reflection.

Thanks for being patient with me.
Jun 9 '09 #7
tlhintoq
3,525 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Reflection;
  3.  
  4. class CallMethodByName
  5. {
  6.    string name;
  7.  
  8.    CallMethodByName (string name)
  9.    {
  10.       this.name = name;
  11.    }
  12.  
  13.    public void DisplayName()      // method to call by name
  14.    {
  15.       Console.WriteLine (name);   // prove we called it
  16.    }
  17.  
  18.    static void Main()
  19.    {
  20.       // Instantiate this class
  21.       CallMethodByName cmbn = new CallMethodByName ("CSO");
  22.  
  23.       // Get the desired method by name: DisplayName
  24.       MethodInfo methodInfo = 
  25.          typeof (CallMethodByName).GetMethod ("DisplayName");
  26.  
  27.       // Use the instance to call the method without arguments
  28.       methodInfo.Invoke (cmbn, null);
  29.    }
  30. }
Jun 9 '09 #8
walentys
9 New Member
Okay, thanks for your help.

I just have seen that most people, including even in this community, frown upon retrieving a variable via a string (its name). I figured the same would apply here. But I guess in some cases it is acceptable for such behavior, especially when it would simplify the code so greatly.
Jun 9 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
674
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
9
2912
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
2
2429
by: Test User | last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people as possible) I am somewhat familiar with Access 2000, but my latest project has me stumped. So, I defer to you...
6
2106
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
17
2674
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
17
4824
by: roN | last post by:
Hi, I'm creating a Website with divs and i do have some troubles, to make it looking the same way in Firefox and IE (tested with IE7). I checked it with the e3c validator and it says: " This...
6
2121
by: JoeC | last post by:
I have a question about designing objects and programming. What is the best way to design objects? Create objects debug them and later if you need some new features just use inhereitance. Often...
0
2065
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
19
3134
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
8
2207
by: indrawati.yahya | last post by:
In a recent job interview, the interviewer asked me how I'd design classes for the following problem: let's consider a hypothetical firewall, which filters network packets by either IP address,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.