Skip to main content
added 1691 characters in body
Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Actually your goal is fine so long as you understand what it will get you and what it will cost.

But you're going about it the wrong way. You want your business layer to be independent of your persistence layer? Fine. Then stop thinking about springSpring. Stop thinking about persistence.

Make your game work without any persistence at all. Work out what your business rules are. What your model needs to be. Sure state dies when you turn off the computer but you can still get pretty far this way.

Now that you know what your game is what do you want saved? What API should you offer so that state can be saved and rebuilt. Done this way you focus on your real needs and not on what some framework offers out of the box.

You may have to do more work. You may miss out on some springSpring features. If you want this to work you have to be ok with that.

But now, if you ever want to, you can swap out springSpring for something else. You could even create your own persistence code.

I know this works because I've done it. It's not cheap. But it works. Sometimes it's even worth it.

What does this get you?

You create a place in the code that doesn't know about Spring and doesn't know about persistence then changes to those things won't impact that place. In that place you put your business rules. No one should be able to look at the code for this place and tell that you're using Spring or Mongo DB. Do that faithfully and you won't be coupled to either one. At least not here. Do this and your business rules will be protected from change that has nothing to do with your business rules. As a bonus, people that haven't studied Spring or Mongo DB will still understand the code here.

What does this cost?

By deliberately avoiding making choices to make things easier to use Spring or Mongo DB you end up having to create a translation layer between your pristine business logic and code that bows to the needs of Spring and Mongo DB. This translation layer is what will be impacted by changes to Spring and Mongo DB. Creating that layer is work. It comes at a cost. It robs you of some of the tempting benefits of these tools. If you're fine being as tied to these tools as you are to your programming language then that work has been wasted.

No autowiring?

If you're surprised that I have kicked not only Mongo DB but Spring as well out of your business rules since Spring isn't just about persistence then let me be clear: construction logic doesn't belong in your business rules any more that persistence logic does. Spring can help without your beans knowing it exists.

There are ways to make use of all of these tools without letting them seep into every part of your code base. But fighting the tools desire to be everywhere is work. You don't get isolation for free.

Actually your goal is fine so long as you understand what it will get you and what it will cost.

But you're going about it the wrong way. You want your business layer to be independent of your persistence layer? Fine. Then stop thinking about spring. Stop thinking about persistence.

Make your game work without any persistence at all. Work out what your business rules are. What your model needs to be. Sure state dies when you turn off the computer but you can still get pretty far this way.

Now that you know what your game is what do you want saved? What API should you offer so that state can be saved and rebuilt. Done this way you focus on your real needs and not on what some framework offers out of the box.

You may have to do more work. You may miss out on some spring features. If you want this to work you have to be ok with that.

But now, if you ever want to, you can swap out spring for something else. You could even create your own persistence code.

I know this works because I've done it. It's not cheap. But it works. Sometimes it's even worth it.

Actually your goal is fine so long as you understand what it will get you and what it will cost.

But you're going about it the wrong way. You want your business layer to be independent of your persistence layer? Fine. Then stop thinking about Spring. Stop thinking about persistence.

Make your game work without any persistence at all. Work out what your business rules are. What your model needs to be. Sure state dies when you turn off the computer but you can still get pretty far this way.

Now that you know what your game is what do you want saved? What API should you offer so that state can be saved and rebuilt. Done this way you focus on your real needs and not on what some framework offers out of the box.

You may have to do more work. You may miss out on some Spring features. If you want this to work you have to be ok with that.

But now, if you ever want to, you can swap out Spring for something else. You could even create your own persistence code.

I know this works because I've done it. It's not cheap. But it works. Sometimes it's even worth it.

What does this get you?

You create a place in the code that doesn't know about Spring and doesn't know about persistence then changes to those things won't impact that place. In that place you put your business rules. No one should be able to look at the code for this place and tell that you're using Spring or Mongo DB. Do that faithfully and you won't be coupled to either one. At least not here. Do this and your business rules will be protected from change that has nothing to do with your business rules. As a bonus, people that haven't studied Spring or Mongo DB will still understand the code here.

What does this cost?

By deliberately avoiding making choices to make things easier to use Spring or Mongo DB you end up having to create a translation layer between your pristine business logic and code that bows to the needs of Spring and Mongo DB. This translation layer is what will be impacted by changes to Spring and Mongo DB. Creating that layer is work. It comes at a cost. It robs you of some of the tempting benefits of these tools. If you're fine being as tied to these tools as you are to your programming language then that work has been wasted.

No autowiring?

If you're surprised that I have kicked not only Mongo DB but Spring as well out of your business rules since Spring isn't just about persistence then let me be clear: construction logic doesn't belong in your business rules any more that persistence logic does. Spring can help without your beans knowing it exists.

There are ways to make use of all of these tools without letting them seep into every part of your code base. But fighting the tools desire to be everywhere is work. You don't get isolation for free.

Source Link
candied_orange
  • 119.7k
  • 27
  • 233
  • 369

Actually your goal is fine so long as you understand what it will get you and what it will cost.

But you're going about it the wrong way. You want your business layer to be independent of your persistence layer? Fine. Then stop thinking about spring. Stop thinking about persistence.

Make your game work without any persistence at all. Work out what your business rules are. What your model needs to be. Sure state dies when you turn off the computer but you can still get pretty far this way.

Now that you know what your game is what do you want saved? What API should you offer so that state can be saved and rebuilt. Done this way you focus on your real needs and not on what some framework offers out of the box.

You may have to do more work. You may miss out on some spring features. If you want this to work you have to be ok with that.

But now, if you ever want to, you can swap out spring for something else. You could even create your own persistence code.

I know this works because I've done it. It's not cheap. But it works. Sometimes it's even worth it.