Posts Tagged ‘java’

The Context

Posted in architektura, domain driven design, java, programowanie on March 19th, 2012 by Wojciech Soczyński – Be the first to comment

The inspiration for this post came to me mainly because of the discussion in comments which I had on Sebastian’s Malaca blog. We had a little debate there about the famous “getters and setters” duo. In my opinion, you can peacefully write software, completely avoiding them (with the obvious exception for DTO’s). My interlocutors had a little different point of view – they stated, that although you should avoid them, there are some cases when G&S are a must. I came up with classic example of a Human, which we can image as:

Could not embed GitHub Gist 1388156: API rate limit exceeded for (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

As we see in this example, you don’t have any getters or setters, all possible actions of a Human are expressed by the methods attached to its class. OK, everything looks beautiful, but what happens if our walking Human gets hit by a car ? If the injury is serious, he will be taken to the hospital. In the hospital he will be medically examined by some (let us hope) skilled medical personnel. If the injury was real worse, the situation may require to perform an operation on an open heart. Unfortunately our properly encapsulated Human doesn’t expose its internal state of which the heart is part of. So, what can (and does) a surgeon ? He just simply breaks the encapsulation by cutting the chest and gets his job done.

If we wanted to translate (model) the actions of a surgeon in Java code, we would write:

Could not embed GitHub Gist 1392023: API rate limit exceeded for (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

In the above example, Java’s reflection API was used to break the encapsulation of the instance of a Human class. If we dive into the body of the method “operate”, we could see that an exception could be thrown – the IllegalAccessException. This is because the JVM could be configured to ban such usages of the reflection API. In the real world, the family could also disagree to operate the patient.

So much for drawing parallels between the real world and Java code. As we see, we cannot relay on this particular feature of Java’s reflection API. If we want to save our innocent Human being, we have two options:

  1. write getters and setters for the organs
  2. add a new method to the Human class, to let him be operated

Let write some code to see, how could it be implemented:

Kierunek Babilon pt.3 – jak wygląda development w Javie ?

Posted in java, php, programowanie on October 16th, 2011 by Wojciech Soczyński – 32 Comments

Dewelopment w Javie fundamentalnie różni się od flow do którego jesteśmy przyzwyczajeni w przypadku aplikacji Pehapowych. Wynika to przede wszystkim z samej “natury” obu platform – PHP jest językiem interpretowanym, natomiast Java kompilowanym. Wobec tego, tworzenie, czy zmiana kodu wygląda zupełnie inaczej.

read more »

Trzy style

Posted in java, php, programowanie on October 2nd, 2011 by Wojciech Soczyński – 17 Comments

Tak przy okazji refleksji i rozmyślań filozoficznych, postanowiłem zademonstrować, jak w języku pokroju Javy zaimplementować rozwiązanie problemu obliczania ceny wszystkich produktów w koszyku.
read more »

Kierunek Babilon pt.2

Posted in php, programowanie on September 9th, 2011 by Wojciech Soczyński – 16 Comments

Minęło już półtora tygodnia od czasu jak zacząłem moją pracę w Sabre i myślę, że jest to dobry czas by pokusić się o małe podsumowanie tego jakie są moje wrażenia i czy moje oczekiwania, które przedstawiłem w poprzedniej części artykułu w jakimś stopniu miały okazję się spełnić.

read more »

Kierunek – Babilon

Posted in php, programowanie on August 3rd, 2011 by Wojciech Soczyński – 36 Comments

Pewnie zastanawiacie się co ma wspólnego Babilon z PHP i programowaniem w ogólności. Ktoś może sobie pomyśleć, że chodzi może o kryptonim jakiegoś nowego frameworka, albo też odkryłem w sobie talent prozaiczny i zamierzam pisać fantasy osadzone w czasach Hamurabiego.

read more »