Demonstrating open/closed principle

Recently i went for an interview, one of the best actually, one of the practical questions they asked was around Open/Closed Principle of SOLID.
The SOLID principles is one of the most asked questions in an interview for a O-O software developer. Most companies ask you to define or explain them and few ask to demonstrate them.

In this interview, i was asked to first explain what the “O” in SOLID stand for.

software entities(classes,modules, functions etc) should be open for extension and closed for modification.

Then apply it to this problem domain

Given we have a logger, with the following code, that writes to the File System, Expand its functionality to allow us to send email when we do logging.

public interface ILogger
public void log(string $message);

public class FileSystemLogger : ILogger
private readonly string filePath;

public FileSystemLogger(string filePath)
this.filePath = filePath;

public void LogMessage(string message)
using (var streamWriter = new StreamWriter(filePath))

With solid principles in the back of my mind, i know the code for FileSystemLogger can not be changed. But can it be extended?

public class EmailAndFilesystemLogger : FileSystemLogger
public EmailAndFilesystemLogger(string filePath) : base(filePath)

public void log(string message)
//...send email with message

The approach is nice and simple but it has some major drawbacks. First, it violates the single responsibility principle. Second, following this pattern, any future requirement like “add database logging” would add another level of inheritance and coupling. Third, any change to the base class could break everything.
So inheritance doesn’t work nicely here.

What about its partner, composition,

public class EmailAndFilesystemLogger : ILogger
private readonly FileSystemLogger fileSystemLogger;
public EmailAndFilesystemLogger(FileSystemLogger fileSystemLogger)
this.fileSystemLogger = fileSystemLogger;

public void LogMessage(string message)

//...send email with message

This is a better approach. It solves the business requirement but there is no way to perform emailLogger on its own.
So let’s separate it out.

public class EmailLogger : ILogger
private readonly ISmtpClientWrapper client;

public EmailLogger(ISmtpClientWrapper client)
this.client = client;

public void LogMessage(string message)
var mailMessage = new MailMessage {Body = message};

This looks good. Easily testable. What about the business requirement? How do we log to a file and send email as well.
This sounds like a job for Aggregator. Aggregator combines and uses indepedent objects.
SO, an aggregator for our requirement will look like this.

public class AggregatorLogger : ILogger
public AggregatorLogger()
loggers = new List();

public IList loggers { get; }

public void add(ILogger logger)
public void LogMessage(string message)
foreach (var logger in loggers)

This code is easily testable, extendable and adhered all of the SOLID principles.
Full code and tests are on my github.

Thanks for reading.

Rotating developers within a company

I had a thought recently about rotating developers

I believe that there are a lot of good reasons to rotate the developers at your company onto other projects more frequently than you already are. What I mean by “rotate” is that a team member is effectively moved from one project to another. This is usually in the form of a trade. A developer from one project switches places with the developer of another project. They’re still around to help anyone working on the old project, but it is no longer their primary roll.

Just how frequently am I suggesting that developers should rotate onto new projects? In my opinion, a developer should be on a new project every 6 to 12 months. But this is something your company should experiment with to find an ideal length of time.

I don’t want to act like rotating developers is all advantages. But I shall discuss the disadvantages in a future article. Here’s why you should rotate your developers onto different projects:

Rotating developers helps them understand the big picture

Lets go extreme and imagine that one of your developers worked on every single project at your company. They would be intimately aware of how all the pieces fit together. They’d understand why a request to another team is reasonable or unreasonable given their constraints. They would have insight into the best place a feature to be implemented and be able to break down high level requirements into low level stories that are distributed to the rest of the teams. And, the chances that all the pieces would fit together in the end would be improved.

Consider that not all projects are user facing. Some projects are merely APIs for other projects. The people stuck on these API projects have a difficult time seeing how the features they are writing are providing value to the end users. Rotating these developers onto user facing projects will give them empathy for the customers and help them make decisions on their behalf. This decision making advantage will carry oven even if they are rotated back onto an API project. If a developer from a user facing project rotates onto an API project, they can bring a lot insight to the rest of the team for the same reason.

Rotating helps with a shared context

There’s a company maturity level required to even be able to rotate a developer from one project to another. Unless there’s a good support structure (documentation, onboarding, pair programming, etc.), a rotation will not go well. This support structure requires a way to share context. Without this – worst case scenario – it will be as if both developers quit. This would occur if you only had one person teams and after rotation, the two people never communicated with each other. Without being able to share context about where they left off, the ramp up time for being effective on their new projects will be astronomical.

The reality is that any developer is free to quit any time they want. So avoiding rotation does not avoid this concern, it just stops you from dealing with it until it’s too late. Better to deal with this risk head on today than at the worst possible moment tomorrow.

Rotating increases collaboration

With a large enough company it can become possible for projects to depend on each other with limited collaboration. This is a problem and here are a few symptoms of it:

  1. Work that is frequently blocked waiting for other teams
  2. Components that don’t fit together (e.g., an API nobody uses)
  3. Features that nobody uses

Frequent rotation will help alleviate these problems. It will also give developers direct contacts with people in other projects and that can pay off in unexpected ways.

Rotating empowers anyone to fix issues on any project

Once a developer has worked on a project, they will feel comfortable fixing issues on that project. When a company does not rotate developers this is not the case. When a project has production issues the developers of other projects wait for the developers of that project to fix it. This doesn’t have to be the case. With sufficient trust and collaboration, any developer could feel empowered to fix any production issue regardless of the project.

Rotating can reduce employee churn rate

A lot of developers start to look for a new job when they feel their current job has stagnated. It’s no fun to know everything you’re going to do day in and day out for years to come. Another reason developers quit is that they want to work with new people or learn a new technology. Rotating gives a developer all of those opportunities with very little downsides (relative to having an employee quit).

Some projects are less fun than others. If a developer is stuck on a bad project and it feels permanent, they’re likely to look for a new job. But if a new project is 6 months away, the bad project will be temporary and an employee is more likely to stick it out.

Rotating is an opportunity to learn

Having a developer stuck on a project for years is like having a developer live on a little knowledge island. They are learning things that would be valuable to share with others. Others are learning things that should be shared with them. When the organization structures these communication boundaries so developers can’t share experiences, everyone is left to their own devices to learn.

This is inefficient because some islands that others have already learned. Some islands may never learn a lesson that they should.

Rotating gives developers an opportunity to improve code quality

I’m working on a project right now that has had over 4 people rotate on. Each time a new person rolls on, they point out a low hanging fruit for improving the quality and stability of the code base in their first week. Why does this keep happening? Because a pair of fresh eyes can easily see the eyesores that the rest of the team has learned to adapt to over time.

When developers know they will be rotating onto new projects and responsible for sharing context before they leave, they’re going to be encouraged to write maintainable code. It’s far too common for a developer to silo knowledge so that nobody can understand it but them. Frequent rotation reduces this risk by addressing it earlier.

Rotating can reduce ego

Pride can be a good thing when it improves code quality. But ego can get in the way of code quality and cause developers to silo the knowledge of their project. Frequent rotation reduces this problem to a 6 month period because that’s the longest that an individual can “own” their code. I’ve discussed in other articles why code ownership is a bad thing.

I will say that there are more effective ways to deal with this issue (pair programming comes to mind).

Hopefully these advantages have convinced you that your company should be rotating developers onto new projects more frequently. Feel free to reach out to me if you have any questions or concerns.

Literary amble around Paris

They say you can never be lonely if you have a good book in your pocket. And if you are in Paris and the book, in question is “A moveable Feast” by Ernest Hemingway, this couldn’t be closer to the truth.

The first chapter is entitled “A good cafe on the Place St. – Michel”

Now here is a recommendation to top those of Lonely planet!. starting on Rue cardinal Lemoine, you can encounter a variety of literary ghosts, and literary haunts alike, if you know where to look.

If you’ve just arrived in Paris and dont know yet your way around, start the journet by taking the metro to Cardinal Lemoine, in the heart of the Latin Quarter.

From here, walk along Rue Cardinal Lemoine until you reach No.71: in one of the courtyard flats behind the gates, James Joyce finished editing “Ulysses” in 1921. If you are lucky, some unsuspecting frenchman has left the gates open. Then you might be able to walk into the courtyard and look for the original flat marked, “E”. Further long the rue, at No.74, is the apartment where Hemingway lived with his wife Hadley from 1922 to 1923. It’s worth taking a moment to imagine the Paris of twenties, with all the glitz and the glamour, when arties and social butterflies fluttered from one party to the next, dangling pearls bouncing gaily on their bosoms. It was on one such occasion that Jake met Bret in Hemingway’s “The sun also Rises”, Take short detour to no.39, Rue Descartes, nearby, which has a double claim to fame: the poet Paul Verlaine died in this hotel and, moreover, Hemingway used to write in an upstairs garret. From here, walk to Place Cpntrescarpe, wehere you can admire its windswept trees so eloquently described in “A moveabe feast”. Open said book on page 1: the establishment at no. 2- 4 once called Cafe de Amateurs, but now renamed Ccafe Delmas, is described as “the cesspool of the Rue Mouffetard”!. This rather ungenerous description, thather than deterring today’s cleintiele, probably draws literary connoisseurs into the , no doubt ver respectable, Cafe Delmas.

From here, it is possible to follow Hemingway’s own direction towards Place St. – Michel. On the way, ame a stop at No.6 Rue du pot de Fer, which was George Orwell’s boarding house, where he stayed while working as a plongeur, a dishwasher. His experiences of poverty and abandonment are vividly described in “Down and out in Paris and London” (1933). In this insightful book, Rue de Pot de Fer is called ” Rue du Coq D’Oe” and it is filled with eccentic characters and voices of misery. As you make your way past Place du Pantheon, “A moveabe fast” at hand, the anticipation of a good cafe au lait is likely yo be uppermost in you mind. It is worth wating just a little longer. stroll down Boulevard St-Mcihel, past the used-book shops and the gated greenery of the Jardin du Luxembourg (well worth a visit, by the way), until you finally reach Place St-Michel. Here, an absolute must see is “Shakespeare and Company”, a charming little bookshop where you can indulge in English language titles. It isn’t original homonymous shop owned  by Slvia Beach, who publised “Ulysees”, but what a magical place it is all the same. Here, aspiring writers sleep on the rugged old couches on the first floor, in exchange for working in the bookshop. Qui, c’est magnifique ca!.

A nice hot drink is probably a necessity at this point, reminding you that one cant live on Litereature alone!.

Unfortunately Hemingway does not give the name of the “good cafe” that he describes , but the famous “Les Deux magots” is not too far, on boulevard St-Germain. This elegant cafe used to be frequented by the likes of Sartre, Hemingway and Andre Breton and the hot chocolate is well worth the trek.

It is true: literary paris is guarenteed to entertain and fascinate any tourist who has time to dig a little deeper intto this city’s marvelous history.

If you have time, there is another obligatory destination: the Pere Lachaise cemetrey, where grears as Oscar Wilder, Gertrude stein and Honore de Balzac are buried. you may get lost among the graveyard labyrinth, so dont forget to bring a map at the entrance. you might also opt to take a flower with you, as amny so to posr on the final rewsting place of Oscal wide.

So can any city rival Paris on its literary richness.Dublin could certainly put up a fair battle, as could London. I’m off to London, next month, i hope to report on my adventure

Tips to increase the performance of your ASP.NET application

Building an application is easy, however, there are lots of opportunities and hidden configurations which can be tweaked that can make it high performance web application.
I will like to share a couple of these tips

1-      Kernel mode cache – It is one of the primary tools widely used for writing making web application faster. But most of the times, we don’t use it optimally and just leave some major benefits.  As each request goes through various stages, we can implement caching at various level as below

We can see that request is first received by http.sys so if it is cached at kernel level, then we can save most of the time spent on server as http.sys is a http listener which sits in OS kernel and listens the request directly from TCP layer. We can save all the time spent IIS/ASP.NET pipeline, page lifecycle, our custom code, time taken in DB etc. Let’s see how we can implement it.

a)      Go to IIS and select the web site.

b)      Click on Output Cache icon on right under IIS section

c)       In right panel, under Actions click on Add. Following dialog will open

Note – there are some limitation over caching in kernel level. As all the features of IIS are implemented at User level so we will not able leverage any of those. Refer this msdn article for complete list where kernel caching cannot be implemented.

2.  Application Pool Suspension – This feature got introduced with Windows Server 2012 R2 and .NET 4.5.1. IIS provides a setting Idle Time out for application pools which is by default set as 20 minutes. It means that if there is no request for 20 minutes, worker process (w3wp.exe) will stop to save the server resources. But it has a side effect, as the worker process currently stopped, the next request becomes victim because while serving it, worker process is required to restart and initialized. Worker process restart is an expensive and time taking process as it includes lots of tasks like process start, initialize configurations, initialize, load the binaries etc in memory.

This feature allows us suspend the process instead of stopping it.  After suspension, it releases most of CPU and memory which becomes available for other sites hosted on same server. But it is maintained in a state if a request comes, it will become active quickly and start serving the request. It is similar to suspension in windows apps where we have concepts of active and suspended apps.  It helps in two folds, first it allows us to server more optimally by adding more application and even the request which comes after timeout, also served quickly without much difference with active ones. We can configure in any app pool as

Select application pool -> advanced settings


Once upon a time, a man was picking up firewood. He came upon a poisonous snake that was freezing in the snow. He took the snake home and nursed it back to health.
One day, the snake bit him on the cheek unexpectely as he was about to feed it. As he lay injured, he asked the snake, “Why have you done this to me?” And the snake answered, “Look, you knew i was a snake”

Why I Run

I run for many reasons. Firstly I love being outdoors, whether I’m going for a run up through the woods to the park or running along by the coast, i love the fact that it gets me out and into nature, which makes me happy.
I choose races based on where they are and where the run will take me. Trail running is awesome. I did a run in Dun laoghaiare last year which takes you down and up the far side of the beach, they only open the path once a year for the run, it’s one hell of a slog to the top, but it’s so stunning, I like runs that climb, I like the reward of a view.

Beyond enjoying being outdoors I love to go for runs because it’s solitary. I spend a lot of time with other people, which I love, but I do like time on my own. I run a lot in Phoenix park, Dublin. Early morning runs or late evening are the most enjoyable, the park is less busy and weather tends to be perfect fot a good long run. it’s a great way to explore the park and discover hidden places where cars can’t take you.

Running also keeps me sane. It helps me to work things out, if I’m stressed or have a problem or just feeling down, a run somehow helps me to reach a solution or see another way to approach things. I always feel calmer and stronger after a run, I’m a very hyper person so anything that calms me down and uses up my energy is always a good thing.

Bottom line is that running makes me feel good. I have never ever felt worse after a run than I did before it. I might feel knackered and my legs might be banjaxed but I will always be in better form after a run. There are days when you just aren’t in the mood and can’t muster the wherewithal to head out, some days the mood wins and I stay on the sofa. And some days I say to myself, “just put your gear on,play some good music and see how you feel”, I know as soon as I have my trainers and music on it’ll happen.

To be honest I wouldn’t refer to myself as “a runner” I’m much more of a plodder. I’m not a natural runner. I’m not one of those tall, lean types who seem to waft along effortlessly. I’m muscular and have a heavy footfall, I huff and puff and sweat a lot, it’s not a pretty picture! But I have good endurance, I last the distance.

I’ve always been a sporty, so have always done something. I love walking, cycle a lot, play soccer and love occasional hiking/mountain climbing if i have the company but when I started working 9-5, I just wasn’t getting time to do any of that. So I started running home from work as it was a handy way of getting my fitness in and it was a great way to get to explore Dublin and the rest of Ireland. On heavy rain or snow days, I work out at my local gym in City centre at Jervis, i tend to do mostly core exercise and finish with some cardio. I try to exercise three to five times a week.

When it comes to diet and fitness I do work hard at it but only because it makes me feel great and the rewards are worth it. I’m always trying to eat better and healthier. I am fitter now than I’ve ever been. And I feel so good for it. My diet mantra is pretty simple: try and cut out the crap, so less refined stuff and more vegetable and fruit and natural stuff as possible. If it makes me feel good I eat it, if it doesn’t I don’t. Coffee and booze would be my toxins of choice, and I love chocolate, cream and cheese, but try to limit them all.

I always need an event to train for, if I didn’t have a goal to work towards I wouldn’t be as motivated, when I don’t have a race to work towards I can get lazy and slack off. When I don’t run I don’t feel so good in myself, both physically and mentally. I fell bloated, tend be grumpy and aggressive. That’s why it’s the mental benefits that I miss when I don’t run.

I like achieving things, it makes me feel good, and one of the best benefits of running races for me is how it has boosted my confidence. Tough races make for good mental training, and for me that carries over into the rest of my life. Not to sound too self-helpy, but it gives you great self-belief. Whether it’s your very first race or your 50th, there is always a point in a race where you think, ‘This is tough I’d like to stop’, but you choose to overrule that thought and you just keep on putting one foot in front of the other, it doesn’t matter how slowly, progress is progress!. Running has taught me a lot. You’ve always got more in the tank than you think, dig deep, tough it out and you’ll get wherever you want to get to.