Archive for single responsibility principle

Decorator Pattern and AOP considered equivalent

Posted in Paradigms with tags , , , on September 30, 2009 by moffdub

Every time I have looked into doing or learning about aspect-oriented programming, I’d be drowned in an obfuscated sea of specialty vocabulary (aspects, advice, pointcuts) and reflective black magic. It would turn me off. I always prefer to learn things the hard way. That way, you truly understand what is happening under the hood.

This isn’t to say that I haven’t understood AOP. I get it: there are certain cross-cutting concerns, the most typical example being logging, and objects throughout your system are often polluted with calls to a logger in addition to performing their normal function. This is rightly said to violate the Single Responsibility Principle. And any friend of the SRP is a friend of me.

So the idea is to extract these calls into an “aspect” and let the other objects focus on their work. See, the idea is not foreign, but its execution was because there are no examples anywhere that don’t involve reflective meta-magic. I want to know the basics!

Read more »

I can’t believe I get paid for this

Posted in Design Issues with tags , , , , , on January 6, 2009 by moffdub

Greetings ladies and gentleman, your favorite bitter clinger is here and back for 2009 with new material. Watch for a new episode of Nowhere To Run this Saturday.

I arrived back at work, after a two-week vacation, fearing the worst: public static everything, classes that I had carefully crafted to have one responsibility now having two or more, bloody red bars all over my unit tests, long parameter lists.

The damage wasn’t as widespread as I imagined. I wasn’t the only one on vacation, after all. There were scattered unit test failures. There is only a couple of slightly long parameter lists. There was even one constants class inheriting from another constants class, and based on its usage, I actually don’t have a problem with this.

Read more »

The Abstraction-Implementation Dichotomy

Posted in Design Issues with tags , , , , on December 17, 2008 by moffdub

Unlike most weeks, I haven’t been writing a post in my head since Saturday. I am quite happily absorbed in design and coding efforts at work. I just started thinking about what to write tonight when I was leaving this morning.

Still, there wasn’t anything compelling that I had mulled over so far this week that I could shape into a post. So instead, this post will be more of an observation, and we’ll see where it goes from there.

A Curious Dichotomy

Seems to me that there is a curious dichotomy between how to design a class and how to design an interface.

Read more »

Follow

Get every new post delivered to your Inbox.