0

Let's say for example that I'm making a tile map editor.

We have the editor, which handles the drawing of the tiles, and we have the tileset which is used to determine what tiles are drawn.

The editor needs to depend on the tileset to know which tiles should be draw, and the tileset needs to depend on the editor to know the dimensions of the tiles to be drawn, as well as other minor details.

This creates tightly coupled code. Is this a code smell? If so, how do I resolve it?

Do I stuff everything into a large class? Do I use a mediator to communicate between the two classes?

CodingMadeEasy
  • 2,257
  • 4
  • 19
  • 31
  • This is related to your question: http://stackoverflow.com/questions/2052579/circular-dependencies – Pedrom Nov 12 '15 at 20:18
  • @Pedrom No it's not. That's a circular dependency based on references. I'm taking about between classes. Completely different. – CodingMadeEasy Nov 12 '15 at 20:30
  • Did you read the PDF showed in the answer? http://www.objectmentor.com/resources/articles/granularity.pdf . The strategies to solve circular dependencies between modules are similar to the ones for classes. Here is another reference talking about the subject: http://tutorials.jenkov.com/ood/understanding-dependencies.html – Pedrom Nov 12 '15 at 23:04

1 Answers1

-1

Write your tile-set first complete with tests, then move on to the editor. In so doing you will have solved your problem without even considering it.

Rick O'Shea
  • 1,410
  • 19
  • 15