Showing posts from September, 2014

JavaScript Module pattern for Java Developers -- Part 1

Lately I have spent some time figuring out what a JavaScript Module pattern is as well as its purpose. After that I decided to write down the nitty-gritty.

Let's take a simple example of a Java BankAccount class. It has two private fields to store the owner of an account and its balance. In some real-world application a reference to a more elaborate data type such as a Client class which holds some other useful data can be used instead of name and BigDecimal class should be used for precision purposes. However for our discussion a simple String and double would suffice.

This class has two private fields to store its data. It is important that the balance field is hidden from the outside world in order two prevent incorrect manipulation of the account. This is done using a private keyword. However, the account should be manipulated somehow, so the class exposes three public methods to work with balance, which allow to increase and decrease the deposited sum in the correct way as w…