Friday, 12 June 2015
Single responsibility principle
Spring framework has been with me since my first day of my work experience. Dependency injection is the main reason why Spring has become so popular. So why is spring considered to be a higher level of OOPs rather than an add-on ? The answer lies in "Single responsibility principle".
When I started with writing a new page with a new approach from the normal CRUD backing beans, first thing came to my mind is implement all the add and modify functionality inside one bean. So in this way we can save some memory by using boolean variables that separate functionality. It is like a single Government office with two doors and only one of them will open based on the type of Token number.
This is a very feasible option and a very good way to make things work, until a door gets closed accidentally. Now this is where the office needs to be deleted into two offices with another set of officers working. This is where the need for "Single responsibility principle"arises, each class should do only one kind of work. This is a very important principle while creating Objects.
What Spring does is it provides beans whenever needed and since they are dedicated beans, serving single purpose can completely remove dependency.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment