Tag: software design

  • Object Orientated Design and SOLID Principles – Dot Net Curry

    Object Orientated Design and SOLID Principles – Dot Net Curry

    I read DOT NET Curry on a regular basis. One of the things that I think is really important to understand is object orientated design and the SOLID principles originally documented by Uncle Bob Martin.

    I’m not going to repeat what has been said by others, this blog will focus on some (hopefully) well thought out examples, but this post links to some of the resources I have found interesting. There is a wealth of information on DOT NET Curry.

    Why should you care about SOLID principles? Isn’t it just something else to remember? The main thing in my mind is that it changes your way of thinking away from the existing code into more about what the code should be doing. Also having more objects, but better named, shorter and simpler with less dependencies really is a breath of fresh air – it makes a system really reliable and easy to maintain if you can read the code. In my view, all developers should study SOLID principles to understand just how readable your code could be, before you decide if you should use this or not. Code readability, whatever methods you use, is very important. If your code is readable enough, you can spot many of your remaining bugs just by reading it.

    For those new to object orientated design, I highly recommend Head First Object Orientated Analysis and Design on my Software Architecture and Design Books page.

  • How Do You Think About Software Changes?

    How Do You Think About Software Changes?

    I’ve come across a lot of developers who think about changes in terms of the existing software. While its important to assess the impact of any changes, its not the whole story.

    How do you think about your software and how to change it if a new requirement comes up for example? Are you an inside out (or bottom up) developer, or an outside in (or top down), or a little bit of both?

    If you have to make changes to meet a new requirement what do you think of first? The requirement or the existing software? A lot of developers I meet think in terms of the latter. Perhaps they think its risky changing software, so they want to change a bare minimum of what already exists. Perhaps they think existing because its there to look at as opposed to a new design that is still in the abstract.

    I think its very worthwhile to think about the software design in terms of requirements if you can.

    For example, if a web page (or portion of) is handling one thing at present, say GCSE results, and you need to cater for other types of results that have a different grading structure or possibly a free format grade rather than the usual A+ to F which at the moment is handled by a drop down. How would you meet this requirement? There is no right answer with design. It depends on your overall requirements and purpose of the system.

    Many developers will just make a minimal change to existing pages to handle the new requirement, but the problem is, this makes them more complicated. More complicated means you are less likely to re-factor and improve the design in the future, because there is a greater risk of breaking something. As the design gets more complicated, it takes longer and longer for programmers to read the code and understand the impact of any changes. Eventually it gets so complicated its impossible to understand and maintain, and even the simplest of changes take a lot of time and involve a big risk of breaking something.

    So often, a good strategy is to listen to the user requirements, consider making a new page (or component) for that requirement, and sharing other common components between the two pages (or components). Either way, you need at least one strategy to handle the complexity of non-trivial systems, otherwise they will get out of hand. If you put all your code in one place (in the code behind of an ASP.NET page) you are at risk of just modifying that code when requirements change because it sure costs a lot of thought to do anything else and in the end you lose because the software is impossible to maintain and needs junking and / or totally re-writing.

    How to avoid this? You could start by starting to refactor it out into different libraries, by improving it bit by bit over time.

    I am going to cover this subject a lot more in this blog. Thats what the upcoming series of posts on design are about. What a layered system looks like and how to start working towards this kind of design, without junking your existing software.

  • Software Architecture and Design

    Software Architecture and Design

    There are two main reasons why I created this blog. I wanted to pass on my experience, and also engage in conversation with other developers about:

    1. Software Architecture
    2. Software Design

    What is Software Architecture?

    By software architecture, I mean the format and layout of physical systems, e.g. Visual Studio Solutions consisting of individual projects, classes, methods and visual components. Higher level architecture, such as the relationship between different component parts of a system, are also covered.

    What is Software Design?

    By software design, I mean the process and results of this process that make us arrive at a particular architecture.

    I do intend to cover detailed design or individual parts of systems, but less so than the above.

    So to summarise:

    1. The software design process, leads to:
    2. High level architecture, leads to:
    3. More detailed design of individual components into layers and individual classes and methods
    4. Not forgetting tests, both of the unit kind and acceptance and regression tests

    Upcoming blog posts

    I have two series of blog posts planned which I will do this year:

    1. Layered Architecture Examples in .NET – taking the reader through the thought process and trade-offs involved in making a layered system design
    2. I have long been a fan of TDD, clean code, DDD (domain driven design) and having the code document itself and show intent as clearly as possible, to me, this results in the best quality software. However on some projects I have worked on, using tools like NCrunch, result in programming teams focussed on ensuring that every possible line of code is tested, and a suite of tests that effectively multiply the size of a system 5 times (needing 5 lines of code to test every line of code in the system) and a project that focusses inwardly on itself rather than outwardly to meeting user requirements. Tests should just be business level – these are the important items that need implementing properly and covered by tests, not every single line of code (in my view). I have recently read a book on BDD (see the section on Software Architecture and Design Books on this blog) that puts testing at the right level in the project, i.e. at the business level, and across all members of the team, not just the developers, from the very start of the project. I would like to review this book and these concepts in a series of blog posts later this year once I have some practical experience of it.

    Hopefully this will just be the start. I hope to expand on these two subjects and make them the main core of this blog guided of course, by user feedback via the comments on this blog.

    Regarding BDD, a good place to start for a .NET developer is the Spec Flow project. The subject of software design and architecture is clearly a big subject that will take time to cover properly, especially when I consider that there are many other areas that a developer comes across in day to day work, plus the fact I would like to help beginners with this blog and I have a full time job as well. Watch this space!

  • Software Architecture and Design: Where to Start

    Software Architecture and Design: Where to Start

    In time one of the main themes of this blog will be about software architecture and design.

    There are many different terms used to describe this important subject and sometimes they are used interchangeably. In this blog, “Software Design” will mean the internal design of programs, “Software Architecture” will mean the organisation of, and relationship between, different programs used to make up a system.

    So “Software Architecture” refers to the overall system design and “Software Design” refers to the design of objects and components within a program used in the system.

    I think this is a very important topic that is not covered that well elsewhere. A lot of example code you see on the web, or books you read about programming, even examples from professional companies that sell third party libraries for example, include anything about architecture or design.

    So why is it important?

    Well in order to write software you do some kind of design whether you think about it or not, I think its important not to take the default option and not think about it before you start writing code. The time spent writing the system, the efficiency of it and the ease of maintenance are just a few things affected by good architecture and design.

    Wikipedia has a good definition of software design, but the things we are interested in are basic architecture and the SOLID principles for design which help you to organise your code in a much better way than the default “Thick Client” way. The idea being that you use object orientated design to organise your code into more but simpler classes that are easier to work with than just having one big page class and throwing everything in there. Managing the dependencies between these different classes, components, objects (call them what you will) is one of the key software design skills.

    Diagram showing typical multi layered architecture
    There is no right or wrong way to do software architecture and design, but having thought about it, you will at least have a plan and you will avoid the default option of the “Thick Client” approach that I have seen and laboured with so many times in the past for various customers. “Thick Client” is where you just use the “Code Behind” option in Visual Studio and build up an application on a page by page or form by form basis. All the logic, everything goes into the pages, so in the end the system is one unmaintainable morass because all the features of the software are spread across many different places. I worked on a ten year old system that had been developed like this a few years ago, and despite working on this system for months, there were so many interdependencies in this system, it took hours and hours of reading code to understand what was happening before one dared to make a change. This system was slow, unreliable and making changes to this system cost 100’s of times more than what they should have cost, had the system been designed better in the first place and up until my joining the project nothing at all had been done to improve matters. The “Thick Client” approach is only really suitable for prototyping and only then if the prototype is going to be thrown away (not something I do very often – Agile thinking takes a prototype and develops it into a real system, so thick client is most definitely out at any point).

    Diagram showing typical layered software architecture
    Please note, I am not calling anybody “Thick” here, certainly not my customer. Thick Client refers to the fact that all the code, everything, is in the Client (User Interface) layer. One of the goals of software design is to separate out the business logic (and other components such as data access) from the code that must be there to glue everything together and to make it work – the “Plumbing” for want of a better term. This is a topic that will be explored thoroughly in future posts.

    So what’s the alternative to “Thick Client”? How can I fix a system that I come across that is bad in these respects? How should systems be designed? Where can I learn more about it? How do I tell the difference between good and bad if I don’t have experience of the good? Where does Agile fit into all of this? How about TDD (Test Driven Development)?

    I will try during the course of this blog to come up with some good posts that answer these questions and more, and also illustrate different aspects of this important subject, with worked examples.

    More on SOLID principles

    If you haven’t heard of the SOLID principles before, there are many resources on the web. Two I have picked on are the MSDN overview of SOLID principles, and Uncle Bob being interviewed by Scott Hanselman about SOLID principles – this also has a transcript in PDF format if you prefer to read rather than listen (I listen a lot in the car when driving out to see customers). I need to go into a separate post to even start to do SOLID justice (and then there is the question of examples). It does take a while until something suddenly just clicks and then you find you think that way automatically. One final link for now on SOLID is the SOLID post on Stack Exchange.