Keep it simple! YAGNI!

image.png

Evergreen on this blog is the Howto: 3-Tier / 3-Layers architecture. But in fact I had some doubts if this usual practice is the best way. Is a three layer architecture with an own DAL always recommendable?

A few days ago I’ve read an interesting blog post which goes the same direction: Keep your code simple!

From Spaghetti-Code to Lasagne-Code

Every developer knows that it’s not necessary to produce a code with 100000 lines for only one function. But it’s possible to reach another extreme: a Lasagne Code. You have Countless layers of code only to make the object move from one layer to the next.

KISS & YAGNI

Before you create an 3-layer architecture without any reason you should ask you one question: Why do I need this?

Why Repository-, Business and Presentation-Layer? Of course it makes sense if you have two Frontends (WebApp and Fat-Client) – but you don’t need it most of the time (YAGNI). The more layers the slower the development process runs. Define another surface here and add a new property there and implement it and only because you want one more field to be shown on the website.

Mh… so how to solve this problem?

I’m pragmatic now and I feel no pain to make the data retrieval directly on the controller (in the sense of ASP.NET MVC). Not until I need the retrieval somewhere else I start thinking about creating a several “Query” class.

I recommend you to do the same with writing processes – do not create a “Command” class before you really need to.

Intent of this: Copy/Paste should be avoided anyway – double the business logic is the wrong way.

And what’s about Unit-Tests?

That’s the point. Without an interface and all this stuff it’s hard to mock. But at least I’m not sure about the real value of Unit-Tests. Countless tests going against Mocks to test at least 5 lines of code.

Integrationtests testing the whole application are at least more significant. These are possible with a SQLLiteDb or you use the usual (but slow) file base and so on.

This should be practicable in a little project without many addictions. How bigger the Backendsystems you need to think about how to test it at the end.

“Poor-Man’s CQRS”

CQRS is a nice concept to divide Queries and Commands (and a lot more).

Daniel Lang (author of the Blogpost “Keep your code simple!”) choose the phrase “Poor-Man’s CQRS” – I like it Smiley mit geöffnetem Mund

What counts in the end…

At the end of the day the software should work. It should attain his goal and it’s not useful to work “by the book” – it depends…

TL;DR

Before you start building numerous layers and put many Mocks and Unit-Tests in it you should ask yourself: Is this really necessary? What’s the aim? But remember to avoid Copy/Paste and age things after the “CQRS” Principe – Queries for reading things and Commands for actions.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by Code Inside Team

Learn more about our team.

Comment on this post

Recent Posts

  • Automated Security Analyser for ASP.NET websites

    Evil Hackers are lurking everywhere and many Web-applications are delicately and share “too much” with the attacker. A quick (first!) overview offers the Tool “ASafaWeb”. All the website does is making a few requests and writing an Analyses including problem solving’s. There are no permanent disadvantages (bad requests/ DoS attacks and so on). Example: KnowYourStack.com ...

  • image1489-570x194.png
    „Sign in with Twitter“ for your own ASP.NET WebApp

      “Sign in with Twitter” is a popular practice to authenticate the users on your website. One advantage compared to an own registration is the lower inhibition for the user. But on the other hand Twitter doesn’t fess up with all the information’s and you will get into a kind of addiction. At the end ...

  • image1485-570x194_thumb.png
    CodePlex is going to be updated

      CodePlex the Microsoft Open Source Project Hosting Plattform hasn’t changed that much in the last few years and for a few times I thought Microsoft stopped the whole developing process. But now I found out that there is still life in the project. Maybe it is because of the success of GitHub or because ...

  • image1474_thumb.png
    What does Adobe in the flash-free web? Magazine-Style Layouts with CSS Regions!

      Adobe is well known for Photoshop and Flash but of course there is a lot more. According to the “Future Post” from Google Adobe declared one of their big subjects on a Blogpost. I’m talking about the W3C Working Draft to CSS Regions. Adobe cooperates with the WebKit Team and W3C on this. What ...

  • image1471-523x194.png
    HTML 5 Games, Tooling & 3D

      Game Developing is an interesting subject for all kind of software developer. But as a web developer without any Flash-skills there aren’t that much starting points. With HTML5 and the combination between Javascript, CSS3 and fast browsers there are the first “robust” HTML5 games. HTML5 games? Is this real? Neowin created a “Top 10” ...

Support us