"Javing" is the present continuous form of "to program in Java".
Here you will find: code snippets, examples, tips, tricks, tutorials, best practices, miscellaneous and much more.
Enjoy your Javing!

Saturday, October 5, 2013

Can you please wrap the gift? It is for my grandma.

Have you ever been in the situation where you have to buy a gift for someone's birthday but you completely forgot until the very last moment?

What if that someone was somebody who you loved so much, let's say your grandma?

Thats not a good feeling uh?

Don't worry this things happen...

Mmmm... yeah... but what to do?
Maybe you have just some time to quickly go to the mall and get something simple and small...

Unfortunately, you know that It won't work, everyone will notice that you forgot to buy a gift and you just bought the first thing you found on your way to the birthday party.

Well... unless you are a gift wrapping expert ;)...

Yeah... I bet you guys know what this blog post is about.

The "Decorator" design pattern.
Imagine, you want to include some additional functionality to a method but you don't want to have impact in what it is already doing.
What you can do, is create a decorator class, that will wrap the original call to that method, and make all the clients call the decorator instead.

Step 1 - Extract an interface that exposes the function you want to decorate.

I want to mention that on the internet I see that the decorator is almost in every post implemented using inheritance(e.g http://java.dzone.com/articles/design-patterns-decorator). It also looks interesting and I will not critic it but I will just paste here a link to an interesting debate on stackoverflow: http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance

Contact me

Name

Email
*

Message
*

About javing

I want to welcome you to my blog.My name is Djordje Popovic, I am a Software Craftsman and an enthusiast of the java programming language.

In 2011 I decided to create javing just as a way to keep track of my studies on the java programming language and also provide support to other fellow students. This blog has being here since the beginning of my career as a programmer. Fell free to make comments or critics to my entries, ill be happy to read them and answer to you.