Skip to main content
deleted 151 characters in body
Source Link
Robert Harvey
  • 200.1k
  • 55
  • 468
  • 679

EDIT - The exact problem

I first thought that giving a simpler example of my problem would suffice but it is enough different to change the design.

 

EDIT - The exact problem

I first thought that giving a simpler example of my problem would suffice but it is enough different to change the design.

 
Fix typos and Markdown formatting (make code look like code).
Source Link
p.s.w.g
  • 4.2k
  • 4
  • 30
  • 40

When I will then call execute()execute(), the Jobs will use the specific information they have to realise the action they are supposed to do.

Then how would you store the concrete type of the Job to use it when I have to modify the specific parameters of that type  ? JobManager only has a list of AbstractJobAbstractJob**.

When I will then call execute(), the Jobs will use the specific information they have to realise the action they are supposed to do.

Then how would you store the concrete type of the Job to use it when I have to modify the specific parameters of that type  ? JobManager only has a list of AbstractJob*.

When I will then call execute(), the Jobs will use the specific information they have to realise the action they are supposed to do.

Then how would you store the concrete type of the Job to use it when I have to modify the specific parameters of that type? JobManager only has a list of AbstractJob*.

Fix typos and Markdown formatting (make code look like code).
Source Link

Let's say I want to create a little application where I can create SquaresSquares, CirclesCircles, and other shapes, display them on a screen, modify their properties after selecting them, and then compute all of their perimeters.

I now have a ShapeManagerShapeManager, instanciatinginstantiating and storing all the shapes in an array :

Finally, I have a view with spinboxes to change each parameter for each type of shape. For example, when I select a square on the screen, the parameter widget only displays SquareSquare-related parameters (thanks to AbstractShape::getType()AbstractShape::getType()) and proposes to change the width of the square. To do that I need a function allowing me to modify the width in ShapeManagerShapeManager, and this is how I do it :

Is there a better design avoiding me to use the dynamic_castdynamic_cast and to implement a getter/setter couple in ShapeManagerShapeManager for each subclass variables I may have  ? I already tried to use template but failed.

The problem I'm facing is not really with Shapes but with different JobsJobs for a 3D printer (ex: PrintPatternInZoneJobPrintPatternInZoneJob, TakePhotoOfZoneTakePhotoOfZone, etc.) with AbstractJobAbstractJob as their base class. The virtual method is execute()execute() and not getPerimeter()getPerimeter(). The only time I need to use concrete usage is to fill the specific information a job needs :

  • PrintPatternInZonePrintPatternInZone needs the list of points to print, the position of the zone, some printing parameters like the temperature

  • TakePhotoOfZoneTakePhotoOfZone needs what zone to take into photo, the path where the photo will be saved, the dimensions, etc...

The only time I need to use the concrete type of a Job is when I fill or display theses informations (if a TakePhotoOfZone JobTakePhotoOfZone Job is selected, a widget displaying and modifying the zone, path, and dimensions parameters will be shown).

The JobsJobs are then put into a list of JobsJobs which take the firstefirst job, executes it (by caling AbstractJob::execute()calling AbstractJob::execute()), the goes to the next, on and on until the end of the list. (This is why I use inheritenceinheritance).

To store the different types of parameters I use a JsonObjectJsonObject :

  • problem : can't store pointers (to Pattern Or ZonePattern or Zone)

Then how would you store the concrete type of the JobJob to use it when I have to modify the specific parameters of that type ? JobManagerJobManager only has a list of AbstractJob*AbstractJob*.

Let's say I want to create a little application where I can create Squares, Circles, and other shapes, display them on a screen, modify their properties after selecting them, and then compute all of their perimeters.

I now have a ShapeManager, instanciating and storing all the shapes in an array :

Finally, I have a view with spinboxes to change each parameter for each type of shape. For example, when I select a square on the screen, the parameter widget only displays Square-related parameters (thanks to AbstractShape::getType()) and proposes to change the width of the square. To do that I need a function allowing me to modify the width in ShapeManager, and this is how I do it :

Is there a better design avoiding me to use the dynamic_cast and to implement a getter/setter couple in ShapeManager for each subclass variables I may have  ? I already tried to use template but failed.

The problem I'm facing is not really with Shapes but with different Jobs for a 3D printer (ex: PrintPatternInZoneJob, TakePhotoOfZone, etc.) with AbstractJob as their base class. The virtual method is execute() and not getPerimeter(). The only time I need to use concrete usage is to fill the specific information a job needs :

  • PrintPatternInZone needs the list of points to print, the position of the zone, some printing parameters like the temperature

  • TakePhotoOfZone needs what zone to take into photo, the path where the photo will be saved, the dimensions, etc...

The only time I need to use the concrete type of a Job is when I fill or display theses informations (if a TakePhotoOfZone Job is selected, a widget displaying and modifying the zone, path, and dimensions parameters will be shown).

The Jobs are then put into a list of Jobs which take the firste job, executes it (by caling AbstractJob::execute()), the goes to the next, on and on until the end of the list. (This is why I use inheritence).

To store the different types of parameters I use a JsonObject :

  • problem : can't store pointers (to Pattern Or Zone)

Then how would you store the concrete type of the Job to use it when I have to modify the specific parameters of that type ? JobManager only has a list of AbstractJob*.

Let's say I want to create a little application where I can create Squares, Circles, and other shapes, display them on a screen, modify their properties after selecting them, and then compute all of their perimeters.

I now have a ShapeManager, instantiating and storing all the shapes in an array :

Finally, I have a view with spinboxes to change each parameter for each type of shape. For example, when I select a square on the screen, the parameter widget only displays Square-related parameters (thanks to AbstractShape::getType()) and proposes to change the width of the square. To do that I need a function allowing me to modify the width in ShapeManager, and this is how I do it :

Is there a better design avoiding me to use the dynamic_cast and to implement a getter/setter couple in ShapeManager for each subclass variables I may have? I already tried to use template but failed.

The problem I'm facing is not really with Shapes but with different Jobs for a 3D printer (ex: PrintPatternInZoneJob, TakePhotoOfZone, etc.) with AbstractJob as their base class. The virtual method is execute() and not getPerimeter(). The only time I need to use concrete usage is to fill the specific information a job needs :

  • PrintPatternInZone needs the list of points to print, the position of the zone, some printing parameters like the temperature

  • TakePhotoOfZone needs what zone to take into photo, the path where the photo will be saved, the dimensions, etc...

The only time I need to use the concrete type of a Job is when I fill or display theses informations (if a TakePhotoOfZone Job is selected, a widget displaying and modifying the zone, path, and dimensions parameters will be shown).

The Jobs are then put into a list of Jobs which take the first job, executes it (by calling AbstractJob::execute()), the goes to the next, on and on until the end of the list. (This is why I use inheritance).

To store the different types of parameters I use a JsonObject :

  • problem : can't store pointers (to Pattern or Zone)

Then how would you store the concrete type of the Job to use it when I have to modify the specific parameters of that type ? JobManager only has a list of AbstractJob*.

explained concrete problem
Source Link
ElevenJune
  • 263
  • 1
  • 3
  • 8
Loading
Tweeted twitter.com/StackSoftEng/status/949169929697275904
added 1 character in body
Source Link
ElevenJune
  • 263
  • 1
  • 3
  • 8
Loading
Source Link
ElevenJune
  • 263
  • 1
  • 3
  • 8
Loading