R
rno
Hi,
I am very much struggling with C#/OOP concepts. Coming from a
(limited) VB6 background, I am trying to make the transition to C#.
Something that still eludes me, despite reading dozens of tutorials on
the subject, is delegates/events. I think/hope I understand the basic
concept of it, but to be honest, in practice it is still mostly
trial-and-error.
Currently, I am rewriting a simple app that I once did in VB6, to C#.
From scratch. I figured it would be a good exercise and at least I
know what I want it to do.
It is a form app (just 1 form), that reads data from a 3-rd party app,
and outputs them to several file formats (HTML and XML for now, more
to come?). When a user presses a button, class A is created. In it, I
determine what options a user selected on the form. Those are passed
to a separate static class OutputOptions, so that I do not have to
pass all kinds of settings on fron class to class. Several overloads
of Class A do the same, but do not take the form as parameter. The
idea is that, when I grow up, I might be able to make the 'business
end' of the application into some dll (or whatever) of it's own, for
use in another app - like the one being examined, in which it could be
used to make it 'self-describing'.
Question: does that make sense? (Do I still make sense to you at this
point?)
Class A evaluates the chosen output format, and based on that, it
creates class C, or class D, or... Class C and D both inherit base
class B, that holds stuff common to either class. A major part of that
common stuff is a class ReadTheData, that does all the actual fetching
of data.
So, in essence, class C and D have a shared 'read-the-data' part, and
a custom 'write-the-data' part. I think that makes sense, right?
Now for the interesting bit:
From the 'read-the-data' class ReadTheData, I want to report progress
back to the form. From the 'write-the-data' classes C and D, I also
want to report progress back to the form. However, I would like to
insulate the UI (form) part from the underlying code. So I tried to
use events. I managed to botch up a way to raise the (same) event in
both the base class of the 'write' classes C and D, and in the 'read'
class B, and I created a separate class 'Listener'. Listener contains
the method that I pass to the event handler/delegate thingie (still
don't quite grasp that) for the 'progress' events, and updates the
form - if it exists.
Question: does that make sense?
If you can still follow me, I applaud you. I realise this isn't a
'to-the-point' question, but rather an inquiry whether I am at all on
the right track, not in code, but in concept.
If anyone would like to comment, I'd appreciate that.
tia
arno
I am very much struggling with C#/OOP concepts. Coming from a
(limited) VB6 background, I am trying to make the transition to C#.
Something that still eludes me, despite reading dozens of tutorials on
the subject, is delegates/events. I think/hope I understand the basic
concept of it, but to be honest, in practice it is still mostly
trial-and-error.
Currently, I am rewriting a simple app that I once did in VB6, to C#.
From scratch. I figured it would be a good exercise and at least I
know what I want it to do.
It is a form app (just 1 form), that reads data from a 3-rd party app,
and outputs them to several file formats (HTML and XML for now, more
to come?). When a user presses a button, class A is created. In it, I
determine what options a user selected on the form. Those are passed
to a separate static class OutputOptions, so that I do not have to
pass all kinds of settings on fron class to class. Several overloads
of Class A do the same, but do not take the form as parameter. The
idea is that, when I grow up, I might be able to make the 'business
end' of the application into some dll (or whatever) of it's own, for
use in another app - like the one being examined, in which it could be
used to make it 'self-describing'.
Question: does that make sense? (Do I still make sense to you at this
point?)
Class A evaluates the chosen output format, and based on that, it
creates class C, or class D, or... Class C and D both inherit base
class B, that holds stuff common to either class. A major part of that
common stuff is a class ReadTheData, that does all the actual fetching
of data.
So, in essence, class C and D have a shared 'read-the-data' part, and
a custom 'write-the-data' part. I think that makes sense, right?
Now for the interesting bit:
From the 'read-the-data' class ReadTheData, I want to report progress
back to the form. From the 'write-the-data' classes C and D, I also
want to report progress back to the form. However, I would like to
insulate the UI (form) part from the underlying code. So I tried to
use events. I managed to botch up a way to raise the (same) event in
both the base class of the 'write' classes C and D, and in the 'read'
class B, and I created a separate class 'Listener'. Listener contains
the method that I pass to the event handler/delegate thingie (still
don't quite grasp that) for the 'progress' events, and updates the
form - if it exists.
Question: does that make sense?
If you can still follow me, I applaud you. I realise this isn't a
'to-the-point' question, but rather an inquiry whether I am at all on
the right track, not in code, but in concept.
If anyone would like to comment, I'd appreciate that.
tia
arno