Skip to main content

Why Software needs an Architecture ? - Testability, Modifiablity, Readability, Maintainability etc.. All abilities !

Hello Enthusiasts ! Happy to see you back :-) ! 

Trust me its going to be the best day today with a worthy read on "a buzz word, that we hear every day in our work or in the world around us often", "a word that never been changed for years and years and stays strong changing the life of human kind", a word that is being the base of any system in the world or even to the universe as a system".

Fine I can hear from your minds to reveal the interesting, core word of the this read and that most valuable word - "Architecture".


Wikipedia says about architecture as -


"Architecture is both the process and the product of planning, designing, and constructing buildings or any other structures. Architectural works, in the material form of buildings, are often perceived as cultural symbols and as works of art. Historical civilizations are often identified with their surviving architectural achievements." 

 :-O Yuhoooo !! Architects out there ! Be proud that we change the world and be the leader of art identified by our architectural works. Being said that the famous book on Software Architecture - "Software Architecture in Practice" by Len Bass 3rd Edition brings out the fact that tomorrow's world and our life is decided by the architects of today !

"Good judgment is usually the result of experience. And experience is frequently the result of bad judgment. But to learn from the experience of others requires those who have the experience to share the knowledge with those who follow. -Barry LePatner"

 Agenda:


What is Software Architecture & Importance ?


Something we build, say a building or any product can be built how ever we want. But in practical real life situations, those products are going to be running or operated in the more critical realistic situations. Lets consider a software product being built to a customer, with lots of constraints of budget while maintaining the reliability and other requirements and they keep changing over the period of time ? Keep on building the floors without deciding the load to the basement would result in a serious risk, same applies in software too.

A Software Architecture helps decide the fundamental structure of a software product being the frame or the structural element deciding the load it can take, the changes it can adopt, the more maintainable it makes the software and decides the abilities of the software to suit all the constraints.



 Is it a responsibility of Architects alone ?


Architects - as the designation mentions, they architect the software product to suit the needs of the customer. They put in all the experience and the knowledge on the technology, tools in the market, latest trends in the domain, solutions that are available as re-usable etc to frame the so called the architecture. An Architect is a true key person in the industry who influence the customer, vendor and the software and finally the end users through the products that they architect. 

Though they are proud that they architect-ed a good structure, their next ability is to communicate the structure to the customer in the way that customer is benefiting, to the vendor in a way that the vendor company is getting the profit, to the developers in a way that the developers can understand to implement the same in the code that they do. Mostly architects makes use of the visualizations to make this happen, the famous "4+1 view" and UML standards are handy tools of an Architect to bring the system to the visualization explaining the,
  • High level of the system
  • Requirements satisfied by the system
  • Benefits given by the system 
  • Use cases the system covers
  • Non functional requirements for the system
  • How the system will be deployed
  • How the system will interact with each other
  • What is the challenges and risk and mitigation structure and etc etc etc
OMG !! A lot of work goes in there, finally when the developer does the code in the way developer likes to do so, its like constructing the building or a bridge on the fly without prior plan. 

So Developers now I guess, the importance of you in translating the architecture into the implementation is the most precious job that brings life to the product with all the abilities proposed.

Okay !! I can get the murmuring minds, "I know the syntax and to apply any requirement the client ask for, why these are important ?" Let me prove this with the example below. 



Proof for the claim - Software Architecture is important - Code Example:


Okay !! theories apart, lets get dirty into code. 

To give the spark on the importance of architecture implementation, I am taking a use case - a simple one to send the OTP to the email or SMS or both. 

Requirements goes like this,
I need to send the encrypted OTP to the user in the mail or in the SMS.

Lets write the code for this in a straight forward approach as below,


Above code have both the proper and improper structure, Lets look into the improper one first.


Lets see what are the problems it gives us,

Problems that are commonly found in this.

  1. Re-usability ? - No none of the functions like generating the OTP cannot be re-used, if I am extending to another channel
  2. Modifiablity ? - Since it is a small use case we can, but imagine this is going to be a very big file with 1000 of lines, then the modifiability is an issue, we can't keep track of what the problem is and where the changes need to be done.
  3. Coupling ? Yes it has all the functionalities coupled into one
  4. Single responsibility ? No all the responsibility is given to the OTPGenerator, even to encrypt the OTP .
  5. Change managed ? Changing any thing will affect any part of code, changes cannot be arrested to certain level.
  6. TESTABLE ? Yes we can test but only if the email is sent or not, we are not able to test if the otp is generated of length 4,    OTP is encrypted?, is mail transporter or channel is working or throwing error ? if throwing error, is my system handling ?    Does changing the configuration, is it changing the behavior in sending the OTP ? etc.
  7. etc., A lot more !!
Below is the unit test written for this, clearly shows that it can only test if the sendOtp is passed or not by throwing the exception and nothing else can be tested.



So we can understand the problems, what is the solution ? Solution is to think on applying the experience through the architecture in the name of patterns and tactics.

Though the use case is small, Let me write all the applicable patterns to make this more reliable. In real world, making such over covered or less covered is a problem, finding the balance between the two extremes gives a good low coupling, good cohesive code and that comes out of the experience.

Lets make use of the strategy pattern, factory pattern / Creator Pattern, Manager / Controller Pattern and lets see how the same use case gets evolved better.




Comments

Popular posts from this blog

How to access the each view of item by position in Recycler View in android ?

How to access the each view of item by position in Recycler View in android ? There are some methods to access the view of each item view to change or update the view during the run time. To access the view of the item view , consider the Recycler view as below, RecyclerView mainRecyclerView = (RecyclerView)view.findViewById(R.id.main_recycler_view); RecyclerAdapter adapter = new RecyclerAdapter(mContext); mainRecyclerView.setAdapter(adapter); main.setLayoutManager(new LinearLayoutManager(mContext));  To access the itemView of each position the following functions can be used,  1. View itemView = mainRecyclerView.getChildAt(positionOfItem);  2. View itemView = mainRecyclerView.findViewHolderForAdapterPosition(Position).itemView;  3. View itemView = mainRecyclerView.findViewHolderForPosition(Position).itemView;  4. Long itemId = mainRecyclerView.getAdapter().getItemId(position);       View itemView = mainRecyclerView.findViewHolderForItemId(itemId);  5. View

A.P.I call or async await not working in Array forEach ?

H ello Readers, Welcome back. You would have wondered why does forEach function on the array does not wait for any asynchronous function even if we provide the async await in the node js. If you are the person, wondered about this ever, this post is right for you. Non working example : Lets consider the below snippet, this will not wait for the asynchronous process to wait. I am making a setTimeout to mock the API call async process. This will result the count as, Output : count = 0 OMG !! Why it doesn't work ? Answer probably might be lying inside the Array prototype from JavaScript. Lets take a look inside the "Array.prototype.forEach" function. From the snippet its clear that, the for loop in which they call the callback function does not wait for the asynchronous process to run in the callback. So this forEach is not build for asynchronous process itself. So can't I use forEach any more for running a asynchronous function ? Answer g

Machine Learning - Types of Learning - Classification Explained

W elcome back to yet another post on the Machine Learning - Types of learning. In the last post we read about Regression type of learning and its various methodologies. If you did not come across that post yet please click on this link to read that. After reading that, this interesting post will seem more interesting 😎 For the people who did not read the previous post short recap: we are seeing each and every type of learning methodology in machine learning that makes the machines to learn. Following types of learning procedures can be identified, Regression - Visited last week - click here to read this Classification  - This is our topic today  Clustering Rule association  Ensemble  Reinforcement Deep Learning Well let's dive deep into the classification. Classification: Before we see how the classification works, Let me tell you in english, in general what does this classification means !. Wikipedia says that classification is the process