I’ve been teaching Java since version 1.0 (yup, I’m that old!), and had been programming for many years before that. When I was younger, I’d hunt for the newest versions of the latest and supposedly greatest languages and tools. I’d want to program everything from scratch too. In my defence, open source software didn’t exist and reusable language libraries were as rare as hen’s teeth.
The more I learned about programming, the more I longed for good, easy-to-use libraries. I got tired of being burnt by the latest versions of development tools that were still riddled with bugs.
Moving to Java was an eye-opener! Here was a portable, platform-independent language with some great libraries. In the early days, the Java API contained just over 200 classes, but it felt like manna from heaven. Since then the APIs have mushroomed in size to well over 4000 classes in Java SE 8.
With all these classes at hand, we can develop a wide variety of applications in Java. On top of the standard library classes, there are countless open source and proprietary libraries to add extra functionality.
Even with all these building block classes, we’re still faced with developing programs in much the same way as we build Lego models — one block at a time. This is regarded as boilerplate code — tedious, repetitive, boring and error-prone.
Surely there must be an easier way? Fortunately, there is: we can use a framework.
What is a Framework?
A framework is a set of well-designed, interoperable classes that provide elegant solutions to common problems within a specific domain.
Domains are areas of interest or concern. If we have to develop a web-based application, that’s a specific area of interest with specific problems we need to address. Interfacing to databases or messaging systems are other domains that have their own problems and own good solutions.
Now we don’t need to build boilerplate Lego code. Instead, we can use framework components that are designed to work together, and they can do the heavy lifting for us.
Pros and Cons of Frameworks
Why do we need a framework at all? It isn’t absolutely necessary to use a framework when developing our applications. But there are some good reasons to use one. Frameworks will:
- Help us focus on the business requirements of our application instead of all the infrastructural code.
- Leverage specialist knowledge of domains. We can’t be experts in every problem area.
- Combine years of experience in the form of design patterns.
- Lower the time to market for our application.
- Lower the cost of application development.
- Help us follow industry standards.
- Avoid re-inventing the wheel.
Using a framework has some disadvantages too. Frameworks will:
- Force us to write our application in a specific way which follows the framework’s architectural approach.
- Tie us to a specific version of the framework libraries.
- Tie us to a vendor (if the framework is proprietary).
- Increase the size of our application. The framework code adds to the footprint.
- Increase the complexity of the application.
- Require a longer learning curve.
Conclusion
There are no silver bullets when developing software. Choosing to use a framework or not is certainly no exception to that. And even when we decide to use a framework, which one do we choose?
Next week, we’ll look at some Java frameworks, and I’ll give you my opinion.
Until then, stay safe and keep coding!