background preloader


Facebook Twitter

Dependency Injection, Annotations, and why Java is Better Than you Think it is · I have a confession to make: I like Java.

Dependency Injection, Annotations, and why Java is Better Than you Think it is ·

Really! I do! That may not be shocking to you. I did help write a book full of Java code, after all. It’s shocking to me, though. My beef was not original or well thought out, but here are my issues, roughly: It’s verbose. That was essentially my view of Java. Public class NumberStack { List<Integer> mNumbers = new ArrayList<Integer>(); public void pushNumber(int number) { mNumbers.add(number); } public Integer popNumber() { if (mNumber.size() == 0) { return null; } else { return mNumber.remove(mNumber.size() - 1); } } } Add some inner classes and interfaces to the mix, and that is what I learned and worked with.

My opinion has changed. Something Peculiar to Java Oddly enough, the tool that changed my mind is only popular because of problems that are peculiar to Java. This class has a dependency in getAfterTaxPay() called EmployeeDatabase. Dependencies in Java are surprisingly strict things. Dependency Injection public class Payroll { ... Conclusion. Build Your Own Dependency Injection Framework! Let’s bust a myth.

Build Your Own Dependency Injection Framework!

There are very good reasons to use CDI or Spring, but dependency injection isn’t one of them. There are a lot of alternatives. And I’m not talking about Google Guice, although that’s a very fine DI framework indeed. Why don’t we write our own DI framework? Can’t be difficult, can it? It’s true: today’s open source libraries make writing your own DI framework incredibly simple. But first I’d like to present you an alternative you’re probably not aware of.

It always pays to have a look into our toolbox before starting to code. Most people who look at the multi-megabyte bundles of Spring and CDI abandon all hope. The ugly truth (that hardly anybody admits) is that doing so almost always adds extra complexity to your program. The other advantage of using a DI framework is that the DI framework can manage the object’s life cycle. Java Design Patterns Simplified: Part 1 of DJANGO Untamed. I am going to write a series of articles this year on my favorite topics of Distributed Computing, Java, Agile, NoSQL, and Garbage Collection (a series known as "DJANGO Untamed").

Java Design Patterns Simplified: Part 1 of DJANGO Untamed

This is the first topic of the series where I will talk about Java Design Patterns. Everyday Issue We all want to be good programmers, but need proper guidance: Design Patterns often confuse usWe know patterns, but hard to get that implementedVery few patterns come into implementation in the natural progressionVast online resources, but what should we follow? Malcom Gladwell mentioned in his famous book "Outliers" (published in 2008) that it takes 10,000 hours of effort to achieve mastery at a professional level. Can We Make the Problem Simpler? If we can’t solve the problem, let's make it simpler. Tied up multiple patterns in a single and simple exampleLink with a real life problem. Java, JVM and beyond » SOLID- Open Closed Principle. Open Closed Principle (OCP) states that, Software entities (Classes, modules, functions) should be OPEN for EXTENSION, CLOSED for MODIFICATION.

Java, JVM and beyond » SOLID- Open Closed Principle

Lets try to reflect on the above statement- software entities once written shouldn’t be modified to add new functionality, instead one has to extend the same to add new functionality. In otherwords you don’t touch the existing modules thereby not disturbing the existing functionality, instead you extend the modules to implement the new requirement. So your code is less rigid and fragile and also extensible. OCP term was coined by Bertnard Meyer. How can we confirm to OCP principle? Its simple- Allow the modules (classes) to depend on the abstractions, there by new features can be added by creating new extensions of these abstractions.

Let me try to explain with an example: Suppose you are writing a module to approve personal loans and before doing that you want to validate the personal information, code wise we can depict the situation as: Design_Patterns_For_Dummies.pdf. Design Pattern Quick Guide. Design patterns represent the best practices used by experienced object-oriented software developers.

Design Pattern Quick Guide

Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time. What is Gang of Four (GOF)? In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson und John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four (GOF). Program to an interface not an implementationFavor object composition over inheritance Usage of Design Pattern Design Patterns have two main usages in software development. Common platform for developers Design patterns provide a standard terminology and are specific to particular scenario. Best Practices Types of Design Pattern Implementation.