Dependency Injection Is More Than Wiring Components
Dependency Injection is widely used nowadays. However, at least in the Java EE space this is narrowed down to "wiring components". I think configuring beans and injecting simple types is at least as important. The alternative is to read in configuration properties from files. Here is why I think DI is the much better approach for that:
- Every project with a certain complexity has this problem. It needs to be adjusted to different users, use cases etc. A common problem should have a standardized solution
- Reading in configuration files is not that easy. You have to handle exceptions if the file does not exist. You need to figure out what to do if a certain value is not set. You might want to have multiple files that can override configurations. I have to admit that I have seen projects in which the most complex code handled the configuration. Spring's XML configuration is already a powerful solution for this. And if you want to use properties files: The PropertyPlaceholderConfigurere allows to use those for configurations as well without writing any code. The PropertyPlaceholderConfigurere is very flexible - see its JavaDoc. But even if this is not enough: Using the BeanFactoryPostProcessor interface you can add your own configuration extensions.
- As configuration is needed almost anywhere the class handling the configuration file becomes a dependency for a lot of classes. This is not a good design. Using DI the configuration will be injected and there is no such dependency.
- Testing will also be hard if each class depends on the class handling the configuration. You will need a complete and correct configuration even for the smallest unit test. Otherwise the configuration cannot be read in. Changing the configuration for a specific test will either be impossible or the code for the configuration will become even more complex. Using the DI approach this is no problem as the configuration is injected and you can easily inject different values.
Of course this is not apparent during a short demo - but in real life DI for these kinds of applications it is a huge advantage.
Labels: Configuration, Dependency Injection, Spring
Private or Public Cloud ?
Currently Cloud is to a lot of people synonymous to "Public Cloud" i.e. some company provides virtual machines or a platform to deploy applications on. Examples are Amazon AWS/EC2, Rackspace, Terremark, Google AppEngine, force.com, vmforce etc. But an enterprise can also build its own Private Cloud. Companies like VMware offer all the infrastructure you need - and there are Open Source offering like Eucalyptus or OpenStack. Which route should you take?
Public Cloud Advantages
Private Cloud Advantages
- Getting started is very easy - basically a credit card is all you need.
- Different service levels: While Public PaaS are quite common there is not really a lot of choice for private PaaS.
- Almost unlimited ressources - you can easily add more servers and a lot of them if needed.
- You would think that you have to ship data to the Public Cloud provider - actually using e.g. Amazon Virtual Private Cloud you can connect the Public Cloud to your local network using a VPN. I guess you can trust a computer in the Public Cloud at least as much as a (potentially compromised) computer in a DMZ
- It is a logical next step after outsourcing operations or using hosting solution - it just provides more flexible.
- Demanding SLAs are available for the services. For example multiple data centers for redundancy are hard to do by yourself and costly - but readily available in Public Clouds.
- You can provide exactly the kind of machines you need. A Public Cloud will only provide a pre defined set of configurations which might or might not offer what you need.
- Legal regulations might make using public clouds impossible.
- You might not want to ship your data into the cloud. But: Salesforce is making 2 billion dollar revenue - and the customer store all their customer contacts, order, revenue forecast etc in the Salesforce Cloud.
- Compared to virtualized environment that are usually already in place a Private Cloud offers a self-service portal. So a user can create a new environment by himself. That means complex and unnecessary processes to approve new environments can be short cut and therefore productivity can increase. However, note that this is also the case for Public Clouds and it is a technological solution to an organizational problem.
Maybe the truth is in the middle: Only for high load you might want to offload work to the Public Cloud. But then you would need a common API for the Public and Private Cloud. Also the Public Cloud would need the same access to data as the Private Cloud - which is doable but might not be trivial. And you would still get different latency.
But: Cloud is in its core a business model. Instead of investing in infrastructure you just rent it - which drives down capital expenditure. This can only really be achieved in a Public Cloud because only then you don't own the infrastructure. Also a Private Cloud can only offer as many ressources as you have purchased.
More applications and data than you think might end in the Public Cloud. The most sensitive business data of quite a few companies are in Salesforce already. If important data cloud not be in the Cloud Salesforce would been doomed - but the reality is that they are very successful.
PS: I would like to hear your opinion. In particular if you are interested to give a talk about "How and why we built a Private Cloud successfully" I would like to hear from you!
Labels: Cloud, Private Cloud, Public Cloud
Book Review: 7 Languages in 7 Weeks (Bruce Tate)
I haven't done a book review in quite a while - so I thought it might be time to do one again. I have chosen Bruce Tate's "7 Languages in 7 Weeks". Bruce has written several books before that I found pretty interesting like "Bitter EJB" or "Better, Faster, Lighter Java".
I believe learning programming languages is a good way to improve as a Software Engineer - and it is one of the recommendation from "The Pragmatic Programmer: From Journeyman to Master" by Andrew Hunt and David Thomas. Even if you don't use the language in your everyday work you will get a different perspective on software development and learn new idioms.
In particular if you are used to Java it might be worth investigating a few new languages - especially those that run on the Java Virtual Machine (JVM).
Bruce covers the following languages:
- Ruby: the famous OO language
- Io: a prototype-based object-oriented language
- Prolog: a logic language
- Scala: mixes functional and object-oriented concepts on the JVM
- Erlang: an almost functional language - used for the implementation of RabbitMQ, CouchDB etc
- Clojure: A LISP-like language for the JVM
- Haskell: A pure functional language
For each language there is an introduction and three sections explaining the concepts. The final section wraps up what has been learned and shows strength and weaknesses. All of the material is pretty hands on. I found the best way to use the book is to read it while sitting at the computer so that you can immediately try out what the book talks about. Actually I bought the eBook. So I have the PDF open while I can type in stuff in another window. The book also contains some small exercises for self-study.
Bottom line: This is a great, very hands-on book that I would highly recommend if you want to see what is currently going on in the programming language space or if you are just curious and want to broaden your horizon.
Labels: 7 Languages in 7 Weeks, Bruce Tate
Preview: JAX 2011
The annual JAX conference in Mainz is the main event for Germany's Java scene. For JAX 2011 I had the pleasure to organize the Spring Day again. The schedule contains:
- Agim Emruli will start the day by discusssing "Web, RIA and mobile Aapplications with Spring". The client technologies are constantly evolving and this talk will present an overview about the current state of affairs.
- Then Jürgen Höller will talk about the upcoming Spring 3.1 release. Jürgen is the lead engineer so we will get some information from the source.
- Next is a talk by me about "Spring in the Cloud". I will show why Spring is a good solution for the Cloud and what you can do with it right now.
- Oliver will discuss Spring Data. He is one of the developers on that project which will support relational databases as well as NoSQL databases.
- Stefan Scheidt will show how to create a backend for an iPhone application using Spring Roo. This is a very good show case about Roo's capabilities.
- Finally we will have a panel to discuss any questions and get some feedback. So all the speakers will be there and it will be highly interactive.
There will also be a basic Powerworkshop about Spring. This time I decided to do it based on Spring Roo which in my opinion is a great way to create Spring applications quickly. Also there will be an Advanced Spring Powerworkshop during which I will talk about advanced topics such as Patterns, architecture, migration to Spring etc.
During the conference I will also do a presentation about AMQP and RabbitMQ for Java developers and a presentation about Java PaaS.
Last but not least: We are planning a panel about the next decade in the Java world with Lothar Wieske and Stefan Tilkov. I am looking forward to this and I hope we will have some interesting discussions there. If there is anything you think we should be talking about I would be more than happy to hear about it!
So JAX 2011 will be quite a packed conference for me. But I am sure it will be a very nice conference again and I am looking forward to meet as many of you there as possible!
Labels: JAX 2011, Spring
J for Java |
I for Internet, iMac, iPod and iPad |
Me for me