473,757 Members | 8,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design question

I have a "device" (abstract class) with some "settings"( not sure if
they should be a bunch of properties or a collection). Settings maybe
readonly or read write. I have a "monitor" that polls the (actual
physical) device periodically to detect changes in settings. These
changes should be reflected in my device instance. Any changes to the
device state should be reflected in the physical device. Should also
be able to add and remove settings at runtime.

The goal is to be able to access these objects on a commandline (by
launching an Ironpython interactive session and loading the assembly)
like so...
print Device1.setting 1
Device1.setting 1 = <some value>
Device1.add(new setting)
Device1.newsett ing = <some value>
If I define all the settings as properties in Device. I have a simple
way of getting and setting their values on the commandline. With tab
completion enabled on the commandline, its a very convenient method of
getting and setting values.
The problem is I dont see how I can add new settings (or remove
settings) without replacing the properties with a collection
(arraylist or hastable). But this would break the simple way to access
info on the command line.
It would change to
print Device1.setting s["setting1"]
Device1.setting s["setting1"] = <value>
The user would have to know what settings are available.

Being new to C#, was wondering if there is some mechanism through
which I could preserve the original way of interacting on the console
and be able to add remove settings???

My second problem:
Device1.setting 1 can be changed by the user OR may change on the
device (due to reasons other than a user making changes)

So I have two ways of changing a setting
OnUserChange
set{
_setting = sendToPhysicalD evice(value)
if(_setting == error)
_setting = null
}
OnChangeInDevic e
_setting = value from poller

So I have a feeling I cant use C# Properties to describe my device
settings, which means again I cant support the kind of console
interaction I want to provide.

Or is there some way I can get this to work? If you have got this far,
thank you for your patience and any advise or suggestions would be
greatly appreciated


Nov 19 '08 #1
1 2432
On Wed, 19 Nov 2008 01:47:54 -0800, Klerk <ce*****@gmail. comwrote:
[...]
The problem is I dont see how I can add new settings (or remove
settings) without replacing the properties with a collection
(arraylist or hastable). But this would break the simple way to access
info on the command line.
It would change to
>print Device1.setting s["setting1"]
Device1.settin gs["setting1"] = <value>
The user would have to know what settings are available.

Being new to C#, was wondering if there is some mechanism through
which I could preserve the original way of interacting on the console
and be able to add remove settings???
Not in the current C#, no. The best you can do is write an indexer, that
would allow syntax like this:

Device1["setting1"] = <value>

That's almost as concise as what you want, and not nearly as verbose as
your problematic example, so maybe that would work for you.

C# 4.0 promises better support for dynamically typed languages, in the
form of a "dynamic" type. But I don't think that there will be any sort
of dynanism in the _implementation _. That is, any way for a type to
dynamically add members at run-time (I infer from your question that
Python would allow such a thing, but I don't know Python so that's just an
assumption). So even in C# 4.0, I don't think you'd be able to have a
single type modify itself at run-time with respect to what members it has.
My second problem:
Device1.setting 1 can be changed by the user OR may change on the
device (due to reasons other than a user making changes)

So I have two ways of changing a setting
OnUserChange
set{
_setting = sendToPhysicalD evice(value)
if(_setting == error)
_setting = null
}
OnChangeInDevic e
_setting = value from poller

So I have a feeling I cant use C# Properties to describe my device
settings, which means again I cant support the kind of console
interaction I want to provide.
Well, you certainly could implement a property as you show here. While
it's usually a good idea for fields backing a property to be modified only
from within the property setter, that's not mandatory. You could in fact
treat the property as a sort of cache of the device's value, as you seem
to be getting at here.

Without dynamic member additions, true properties are probably out of the
question for you. But if you implement the design using an indexer,
you'll have basically the same idea, with a virtual getter and setter for
each named "property" (implemented via the indexer's get and set methods),
so the same basic ideas would apply.

Pete
Nov 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

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 generic design patterns that can be used and shared amongst many sub-schemas. For example, the grouping of entities. I may have the following tables: employee, product and client. These tables have no direct relationship with each other. But...
9
2937
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 a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
2
2445
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 experts. I've been asked to create a Daily Log sheet to be distributed to some of our clerks. For each day, the clerk is to log tasks worked on for the day, (i.e worked on the johnson account).
6
2118
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 responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
17
2712
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
17
4851
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 Page Is Valid XHTML 1.0 Transitional!" but it still wouldn't look the same. It is on http://www.dvdnowkiosks.com/new/theproduct.php scroll down and recognize the black bottom bar when you go ewith firefox(2.0) which isn't there with IE7. Why does...
6
2137
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 times when I program, I will create objects for a specific purpose for a program and if I need to add to it I just add the code.
0
2080
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 end of this message, but I will start with an overview of the problem. I've made a content management solution for my work with a decently structured relational database system. The CMS stores articles. The CMS also stores related items --...
19
3173
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 certification, possibly that involves C++, but, if not, C++ and UML. All I could find was Java + UML design certifications (one such is detailed on http://www.objectsbydesign.com/tools/certification.html). Although UML is expected to be language independent,...
8
2235
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, port number, or both. How should we design the classes to represent these filters? My answer was: class FilterRule {
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.