Skip to main content

Posts

Breaking if/else with a Chain

Greetings! There are If/Else or switch statements in any Software. We need to use that logical branching for object oriented programming as well. The question is how do you use that? are they readable? maintainable? or looks beautiful? What I normally see in such codes is those are very fragile, hard to read, ugly. Needless to say about the vulnerability of the branching levels in this case. Most of the developers might add few private methods and call those to show that the code is clean. This can be solved in multiple ways depending on the situation. Simple Conditions When you see such a code, consider it as a candidate for polymorphism. In most of the cases, you can deal this with abstraction. A simple factory will do the rest. Multi level branches Complexity arrives with multi levels. It is quite difficult to identify common factors, abstraction. However, it does not mean you can't do it. It depends on the problem at hand. You might still fix this with a simple interface, using...

What we learned (in each Sprint)

Greetings! Another job change, another team. That is how my career goes as I tend to change jobs (for obvious reasons). This time I'm working with a team where almost everyone is new to the business and product domain. Not only that, more than half of them are freshers. If I don't teach them who will? I have tried various ways to teach the team about the business and product domain (this is even new to me), internal frameworks (again new to me), and other technical aspects. Things we do/ did Clean Code chapter by chapter by each member Domain knowledge sessions with QA/ BA Internal framework sessions by each team member (learn and teach) Continues knowledge trainings (Java, Design Patterns, Angular, any useful technical thing) Gaining knowledge and insights from from other team. (lucky that we have friendly people here) Question of the Day - separate team chat group in which each teammate gets the opportunity to ask a question. (though people often forget this due to busy work)...

Angular - How to create custom form controls

Greetings! If you are working in an Angular project, you surely have created many UI components. We can easily use @Input, @Output to communicate data between parent to child and child to parent. However, we are unable to bind those values directly to angular forms. But, do we realy need to do it that way? Yes! we need, utilizing the form modules is more powerful way to get user input. Then, can't we use our 'normal' components to do the job? No! we can't. I was ashamed to know that I didn't know the existence of the ControlValueAccessor but better late than never ;) Complete code  custom-form-control What is ControlValueAccessor? When you are working with forms in Angular, whether it is template driven or reactive form, NgModel, formControl, formControlName, Angular creates FormControl to track the value, validations etc. Then Angular should have a way to communicate data between actual html element and the FormControl. Angular is smarter enough not to create one t...

Case Study - How to handle concurrent reservation

Greetings! There are multiple domains with reservation build into it, however the problem they face is same. How do you handle when concurrent users try to reserve the same resource? We can see this situation in systems like; Doctor appointment Airline ticketing Movie ticketing Hotel booking Train ticket many more... Depending on how you define the business this again has two paths. Reserve the same resource - exact time slot for a doctor appointment. Reserve with count - 10 patients for a doctor for given timeslot with an appointment number. Let's understand the problem again You are going to watch the latest hit movie. While you are on your way, someone faster than you passed you. Then both of you joined the queue. Unfortunately for you, the person before you got the last available ticket hence you missed the chance to watch the movie at that time. Now imagine there is a fraud happen. Somehow, someone has the same ticket as you have. Sure...

Case Study - URL Shortener

Greetings! There are URL shortning services like https://tinyurl.com/ , https://bitly.com/ for the obvious reason. Shorten the URL to save space! Be it a twitter message, an email, your resume, it is a handy way to give your valuable URL to others. Let's study the underline techniques together. It looks really simple piece of software at first glance, and it is. The real implementation doesn't look that scary. However, overall architecture give us a whole set of ideas. Related articles https://www.slmanju.com/2021/07/design-unique-sequence-with-mongodb.html https://www.slmanju.com/2021/07/basebase62-encoding-with-java.html What does it do? Any URL shortner will have 2 main features. Give a short URL for any given URL. Redirect to the original URL when we enter the shorten URL in a browser. Just 2 features and what is there to talk? That is the interesting part of this. It touches wide range of architecture decisions when we really implement. I personaly haven't experience...