"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!

Wednesday, December 30, 2015

Experimenting with humans and elfs

Everybody its on holiday, just arrived and It seems like I am the only muppet at the office today.Oh, cool some body left a designs patterns book on the desk. Hehehe...

I guess it was that communist elf again. See? that little man even forgot his hat! Wait, hold on a sec... ARGGGHHH...! WednesdayThursdayFriday!! My banana case its empty?????? The elf ate my banana!!!Ok let's calm down its just a banana, the poor guy had to go back to the north pole so probably toke it for the way back.Anyway, what I do to day? Let's see:- Pile of tech debt waiting for a miracle. Uhm... I wonder if Jesus would be able to unblock me if I get started with any of this today.- Second pile of tech debt. Mayyybe, but wait! there are no story numbers there, better I don't mess up with the process ;)- Swarm with the tester that just arrived. Regression testing you said?? Yes, yes... sure, all the suffering will end one day, yep... Ok lets continue this conversation next week.- Pick new story Opsy, board is empty! No BA's around, Well, I better mind my own business then.All right! let's have a look at this book the elf left for me. Strategy, Template, Builder... Wow so many patterns which one I read about?Oh screw the reading!, lets just do some coding. Ok, what I code about? Its xmas, let's think about some xmas related code......Oh screw that too, lets just do some human experimentation or something. Yes, thats it! Let's experiment with humans! No, no better, let's experiment with elfs hahaha.... Im so evil sometimes!So, what about this one?: Imagine I catch that elf and I torture him in a machine that plays christmas carols infinitely and I log all his reactions, like if it was a proper scientific research.Mmmm... sounds like an events driven system to me. Ok! So let's refresh my mind, how did I do events in Java some time ago? Let's spike that a little bit for now, this book may be handy I will keep it close.I said I would create a person, and I would put it in a machine and see how it reacts to the sounds the machine plays. In order to react, to sounds, I better make sure that person has ears(the listener).

Ok, cool. I remember now. So the important thing here its the person because for it to react, it will need to have different types of listeners. But those listeners, may react to specific events only. Well, the events could also be generic something like an interface(function pointer).

Yes, let's keep it simple. I think that is better since the specifics of each reaction could be programmed separately in each different listener...

The listening object(Person) is used by the application code which is what uses it and also where the action of registering the listeners its done(Main and SoundMachine). Also that listening object holds all the listeners in a list and acts as a gateway, to where the events are sent (noticeWhatItsGoingOn() method).

This was Javing's last post of 2015

Merry Xmas and prosperous new Year!

When it’s the 5th one who tells me ‘see you next year’ when leaving the office

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.