OO-Question

  • Thread starter Rasmus Kromann-Larsen
  • Start date
R

Rasmus Kromann-Larsen

Hey,

I just started out using Visual C# (Visual Studio .NET 2003), but am having
a little problem figuring out where to place my datastructure. I've worked
with programming alot before, but this is my first real object oriented
project. To describe my problem, I'll just outline the project I'm working
on. Basically, I'm working on a questionaire program that has a general
static datastructure used for holding the information about the
questionaire. Where do I place this general datastructure? If using several
different classes/forms, I'd have to pass references along between them,
unless I can place it somewhere general.. But OO-programming is all about
getting rid of the global variables :p Um, it's a bit hard to explain the
problem completely, hope some of you people understand this - probably -
trivial problem, and can give me a quick solution :)

Thanks,
- Rasmus.

Ps. I searched around for other newsgroups, but this one seemed to be the
one fitting my problem best - I apologize if this is completely off-topic :)
 
M

Morten Wennevik

Well, to throw a few thoughts

If the questions vary wildly you might want to create custom controls. A
base question control and any number of derived types from that. A
question control would receive information to display from the
Questionaire class (question, images, alternatives etc) and hold the
answer for retrieval. Questions would have no knowledge of eachother (hm,
sub questions might get tricky). The questionaire class would parse any
question documents, create the controls, process and questions and create
any answer documents. Hm, tricky topic. The best solution might be
something completely different.

Happy Coding!
Morten
 
A

Anthony Borla

Rasmus Kromann-Larsen said:
Hey,

I just started out using Visual C# (Visual Studio
.NET 2003), but am having a little problem figuring
out where to place my data structure.

Are you at all familiar with the C# language, or is this your very first
attempt at a project using it ? If the latter, I'd recommend first
completing some tutorials and the associated exercises. A Google search will
turn up many of these.
I've worked with programming alot before, but this is my
first real object oriented project.

So, you're familiar with programming [even GUI-based programming ?], but not
using an object oriented programming language [OOP] ?
To describe my problem, I'll just outline the project I'm
working on. Basically, I'm working on a questionaire
program that has a general static data structure used for
holding the information about the questionaire. Where do
I place this general data structure? If using several
different classes/forms, I'd have to pass references along
between them, unless I can place it somewhere general.

If you're not familar with OOP then it would seem pointless outlining a
possible design for this problem. I'd suggest:

* You first complete some tutorials as described earlier

* Put together a design that will work as a console-based
application [the tutorials will contain suitable samples]

* If it is a GUI-based solution you are after, then a
Windows Forms tutorial is recommended, maybe
even consulting a book like:

'Programming Windows with C#' by C. Petzold
But OO-programming is all about getting rid of the global
variables :p

OOP is about much more than getting rid of global variables [though, to be
fair, OO finds good ways to hide them - it renames them 'singletons' ;)].
Um, it's a bit hard to explain the problem
completely, hope some of you people understand this
- probably - trivial problem, and can give me a quick
solution :)

No, it's not a trivial problem. The solution is the advice I gave earlier.
Ps. I searched around for other newsgroups, but this one
seemed to be the one fitting my problem best - I
apologize if this is completely off-topic :)

Well. if your question is C#-related, then it is on-topic :) ! I suspect,
though, at this stage, you don't have enough OO or C# knowledge to make a
start on your project which is why I again recommend completing a tutorial
or more on C# and/or Windows Forms.

I hope this helps.

Anthony Borla
 
G

Glen Jones MCSD

Rasmus,

First, let me first say that one principle of object oriented design (OOD)
is a single instance class called a "Singleton". This class can be used to
hold information used by all threads. It sounds like this is what you want.
And by the way, yes this is a global. And no, globals are not bad. They
have just been widely miss-used and in C# they are created the first time
they are needed making them hard to catch any errors. I'm sure you can find
many newsgroup threads on Singletons.

As for designing the data structure that depends on the goals your trying to
achieve. For example if a major design goal is speed over flexibility the
hard coding field elements for each question answer may be warranted.

It's your world, make as you see fit. Hope this helps.
 
R

Rasmus Kromann-Larsen

You are a darling - that was exactly the information I needed, thanks alot
:) I have worked with OO-oriented stuff before - but it's just that most of
the tutorials you go through doesn't really implement 'bigger' applications,
where stuff like this might be needed. I have no problem creating the
datastructures myself :)

Thanks a bunch,
- Rasmus.
 
N

Nick Malik

I do suggest one slim book that will really help with OO programming.
It is called Introduction to Design Patterns by Alan Shalloway.

Problems like the one you are facing come up all the time. This book will
give you a good set of "best practices" in OO design, and introduce you to
an
entire body of literature that will get you past the "simple" designs.

(He has a good section on Singletons, as well)

Hope this helps, and good luck.

--- Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top