N
Nick Valeontis
Hi to all!
I am writing an implentation of the a-star algorithm in c#. My message is
going to be a little bit long, but this is in order to be as specific as
possible. My question has nothing to do with the algorithm. It is related to
OOP in c#.
I have created a class named astar.cs. An instance of the class among other,
contains a instance of a class named Input to store the input parameters of
the algorithm and an instance of a class named Result to store the results
of the algorithm. Here is an example of the final result:
------------------------------------------
CAstar astar = new CAstar();
astar.Input.StartPoint = new Point(0,0);
astar.Input.GoalPoint = new Point(500,500);
astar.Space.Addpolygon(100,100,100,200,200,200,200,100);
astar.Space.Addpolygon(... ... ...);
astar.Solve();
if (astar.Result.Successful) { Console.writeln(astar.Result.ExpandedNodes) .
....};
------------------------------------------
I like the fact that input parameters are not messed with results. Results
as accessed as astar.Results.* and input parameters of the algorithm are
accessed as astar.Input.*
In the example above: Input, Space, Result are classes within the class
CAstar, eg:
------------------------------------------
public class CAStar {
.....public class clsResults {...}
.....public clsResults Results = new clsResults();
------------------------------------------
The CAstar uses events to notify controls (textboxes and panels) when data
are changed. I use handlers to capture those events and update the controls
so that I can view the progress of the algorithm. Here is an example:
------------------------------------------ (in a win form):
astar.ProgressMessageHandlers += new CAStar.StringEventHandler(LogHandler);
(...)
private void LogHandler(Object sender, string e) {txtData.Text += "\r\n" +
e;}
------------------------------------------
In the example above, whenever astar has something to report, it calls the
ProgressMessageHandlers (declared as an event). The LogHandler get the text
sent, and presents it to the screen.
So here is my problem.
If an input parameter is changed after astar.solve() is called ( like:
astar.Input.StartPoint = new Point(0,0); ) I want the data in the textboxes
and graphic panels to be updated. BUT, StartPoint is a member of the class
Input, which does not have access to the events of the astar class (since
astar contains Input and not the other way arround). So I cannot call
ProgressMessageHandlers from within the class Input.
BUT, if I add a property in astar class to set the astar startpoint (a
property thru which I could call ProgressMessageHandlers in set{} section),
I lose the versatility of the syntax: astar.Input.* . I would have to type
astar.SetGoalPoint, astar.SetStartPoint, astarGetExpandedNodes and so on
which leads to a complete chaos of properties.
Is there a way to avoid this? I want like to keep access of input parameters
and results separated but I want CAstar to automatically notify controls to
update their data.
Thanks to all who read all of this. I didn't know how to write all of this
stuff in a more compact way.(!)
I am writing an implentation of the a-star algorithm in c#. My message is
going to be a little bit long, but this is in order to be as specific as
possible. My question has nothing to do with the algorithm. It is related to
OOP in c#.
I have created a class named astar.cs. An instance of the class among other,
contains a instance of a class named Input to store the input parameters of
the algorithm and an instance of a class named Result to store the results
of the algorithm. Here is an example of the final result:
------------------------------------------
CAstar astar = new CAstar();
astar.Input.StartPoint = new Point(0,0);
astar.Input.GoalPoint = new Point(500,500);
astar.Space.Addpolygon(100,100,100,200,200,200,200,100);
astar.Space.Addpolygon(... ... ...);
astar.Solve();
if (astar.Result.Successful) { Console.writeln(astar.Result.ExpandedNodes) .
....};
------------------------------------------
I like the fact that input parameters are not messed with results. Results
as accessed as astar.Results.* and input parameters of the algorithm are
accessed as astar.Input.*
In the example above: Input, Space, Result are classes within the class
CAstar, eg:
------------------------------------------
public class CAStar {
.....public class clsResults {...}
.....public clsResults Results = new clsResults();
------------------------------------------
The CAstar uses events to notify controls (textboxes and panels) when data
are changed. I use handlers to capture those events and update the controls
so that I can view the progress of the algorithm. Here is an example:
------------------------------------------ (in a win form):
astar.ProgressMessageHandlers += new CAStar.StringEventHandler(LogHandler);
(...)
private void LogHandler(Object sender, string e) {txtData.Text += "\r\n" +
e;}
------------------------------------------
In the example above, whenever astar has something to report, it calls the
ProgressMessageHandlers (declared as an event). The LogHandler get the text
sent, and presents it to the screen.
So here is my problem.
If an input parameter is changed after astar.solve() is called ( like:
astar.Input.StartPoint = new Point(0,0); ) I want the data in the textboxes
and graphic panels to be updated. BUT, StartPoint is a member of the class
Input, which does not have access to the events of the astar class (since
astar contains Input and not the other way arround). So I cannot call
ProgressMessageHandlers from within the class Input.
BUT, if I add a property in astar class to set the astar startpoint (a
property thru which I could call ProgressMessageHandlers in set{} section),
I lose the versatility of the syntax: astar.Input.* . I would have to type
astar.SetGoalPoint, astar.SetStartPoint, astarGetExpandedNodes and so on
which leads to a complete chaos of properties.
Is there a way to avoid this? I want like to keep access of input parameters
and results separated but I want CAstar to automatically notify controls to
update their data.
Thanks to all who read all of this. I didn't know how to write all of this
stuff in a more compact way.(!)