Cohesion vs Coupling – Separate Concerns

Home / Cohesion vs Coupling – Separate Concerns

Cohesion vs Coupling – Separate Concerns

Programming, Software Architecture
We mention Cohesion and Coupling when we are talking about Software Design Principles. Those two principles were first introduced in the book Structured Design: Fundamentals of a discipline of computer program and system design many years ago, even though the principles were around Structured Programming, they are still valid in the Object Oriented world. Cohesion Cohesion represents the degree of the systematic or logical connection or consistency in the logic expressed in the our code. In other words, it's the level of balance and harmony of the software logic within a module. In a practical example we may say that the modules are cohesive "when a change to A allows B to change so that both add new value". We want our code to be highly cohesive, as the highly…
Read More

How to be agile in 10 basic steps

Agile, Programming
In order to be agile team in today's quite stressful and demanding time, software programming team should try to follow some if not all of the below listed practices in order to succeed: Test-first programming (or perhaps Test-Driven Development) Regular refactoring Continuous integration Follow a Simple design (YAGNI) Pair programming / Code Reviews Sharing the codebase between programmers A single coding standard to which all programmers adhere A common "war-room" style work area. Small Releases Optimize code in the end If followed coherently and constantly, the above listed practices will add more discipline to the team and add quality to the code. The following expanded diagram of all the practices (adapted from the wikipedia source), shows that there are some more points to be taken into consideration. [caption id="attachment_398" align="alignnone"…
Read More

Object Oriented Javascript – Object Creation

Programming
This post is an introduction to the Object Oriented functionality in JavaScript. I will discuss the ways of creating, instantiation and inheriting objects in JavaScript. JavaScript itself doesn't contain the class keyword and there are mainly three ways of creating objects in JavaScript, by using: Literal notation new Object() Object templates Literal notation By using the Literal Notation, the object description is a set of comma-separated name/value pairs. As you may see all this is wrapped inside curly braces. This is an example of instantiation the person object by directly assigning values to properties. Note that at the run time the properties (i.e: name, surname..) will automatically have "get" and "set" functionality, which means that we may assign or read the value from it. In the example is shown as…
Read More

ASP.NET Web Service – Returning properly formatted error message

Programming
Here is the problem: How to properly display a user-friendly error message for an exception being thrown from an ASP.NET Web Service? I know that we shouldn't be really working anymore with ASP.NET Web Services as a huge amount of problems have been solved with the WCF framework. But, for those like me, that are working on some large-scale projects where we are still using some old technology this could be an interesting post. I was kind of surprised the first time I saw an exception being thrown from the ASP.NET Web Service and how it looked ugly when the error Message Box appeared on the Client application (GUI). The Exception.Message contained the internal Web Service stack. The server-side code looked like this: [csharp] [WebMethod] public SomeResultObject SomeWebMethod() { try…
Read More

The anatomy of a Unit Test

Programming
Certainly there are many ways of organizing Unit Tests and it depends both by who writes the tests and the organization within which the project is running, but one thing is certain the goals of unit testing as: 1. Finding Code early: As in Test Driven Development when writing Unit Tests before writing the real code. Doing so we are certain that our use case is going to be verified even before the actual implementation is done. 2. Enable code changes: In case there is some code refactoring in the application, by using unit tests we may and check that everything works properly. 3. Documentation: Every test method should be self explaining (easy to read) and to demonstrate the usage of the underlying system in a very clear way. I…
Read More

Refactoring with Composed Method pattern

Programming
This is my first post about the code refactoring, and I hope that in the future there will be many, as I find this topic particularly important and interesting. I would like to start with one very simple method but perhaps not so often used in the real life programming: Composed Method pattern. One way of refactoring the code, or in our case a method, is by using the Composed Method pattern which goal is to transform the method logic into a small number of steps and at the same level of detail. The consequence is that the method is divided into well-named methods that perform one identifiable task. The result will be a class with (potentially) many small methods, each a few lines long. Composed method pattern is very…
Read More

Composition over Inheritance

Programming
One (clever) question from my colleague during one interview we had days ago was about why is composition preferable over inheritance. On the other side we had a very clever guy as well:) so the answer was pretty much convincing, but at the same time this made me thinking a bit about all of the possible implications and the differences between the two. In my daily working life I am somehow working very often with dependency injection containers so somehow to me the composition comes very naturally, but let's see the differences. So, what it is all about? Both Composition and Inheritance have a major roles in object oriented systems. Probably the main reason of why the two exist is because there is need for code reuse. In effect the…
Read More

Asynchronous execution – Thread creation in Microsoft.NET

Programming
By starting this post, I am still not quite sure what will be the end result, as the topic is quite waste and not that easy. For sure the goal is not to give you every possible example of multithreading in Microsoft.NET, as this is quite difficult and extensive topic, but to list and make you aware of different possibilities we have in Microsoft.NET when new threads are needed. Feel free downloading the source code with fully working examples: agile-code.com_async.zip There are many reasons for using threading. Suppose you are making a network call from an application that could take some time. You don't want to stall the user interface and just let the user wait until the response is returned back. Usually, user could perform other actions on the…
Read More

Entity Framework Code First – Filtering And Sorting with paging (1)

Programming
In the previous post I described a way of how to apply global filters in the DbContext, so I would like to follow up with adding some more functionality and to describe one way of how to create a generic querying and sorting mechanism. This comes really handy when using the repository pattern. Please consider downloading a fully working example of the code covered in this post: EntityFramework_SearchQuery_v1 The main idea is to have a method in our repository that would be responsible for searching and sorting in a dynamic way the data so that there wouldn't be any need of exposing the IQueriable interface to the client because this is usually not a good idea. This method could be therefore reused for any Entity in the Context. To make…
Read More

Entity Framework Code First – Applying Global Filters

Programming
I am currently writing a prototype for an application so I thought it would be good to start using a different ORM than NHibernate and the Entity Framework Code First was the next "obvious choice". Code First is particularly interesting because it allows using POCO object, which fits perfectly with my programming style, as I try to follow as much as possible Domain Driven Development where the well written domain objects have a very important role. Please consider downloading a fully working example that covers all the code mentioned in the post: EntityFramework_GlobalFilter_v1 Recently, while developing a Data Access Layer I came up to an interesting problem: How to apply global automatic filtering to a certain entity in Entity Framework Code First? In other words, how to make sure that an…
Read More
wela-shay harriston.kent