Categories
Software Engineering

Loose Coupling, Why bother?

For me, it all revolves around this.

Build to last, stronger foundations = powerful castle !

But how? everyone is under a crunching time machine, no one cares how you do it, they all want what is done in the quickest way possible.

Sure, it will save you few bucks at first, but as a wise man said to me. A software is a never ending process, even if it is a simple calculator application. You’ll always get to build and build and build and so on…

Okay, all that, but is loose coupling really matters?

For this, let get into another paradigm. How to measure a software’s code quality?

It’s now how fast you coded it in the first place, but the efficiency of implementing client feedback.

That’s how loose coupling came into all this.

All classes have single responsibility and adding some feedback points of a client in some class won’t disturb other methods. And for some reason you decided to port the class to multiple platforms, you won’t have to reinvent the logic, (yes there are other factors too). But generally speaking, a rule of thumb is.

Loose Coupling = Interfaces = Contracts

So you have defined a contract (interface) which is a set of guidelines, and every class implementing the interface has to obey.

This keeps code maintainability, across multiple plateforms, and assemblies, and for some reason you have revise the complete logic of a class, you just don’t have think the logic what, how , when , where.

Just inherit the interface to another class, the methods are there, implement their logic! easy as a pie… 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 06286 20899 86280 34825 34211 7067

Categories
Uncategorized

The Quest for Repository pattern


So it all started with the hype of design patterns and a new project I was going to work on. Truth be told I’ve never worked on repository before and didn’t found a perfect implementation for it as well.

There are many concepts around internet, like you should make generic repositories and the creation of services.

But be aware my friend, generic repositories are never the answer to any project, as I have learned and read in some book maybe in Programatic Programmer or Code Complete, a project never ends!

Maybe you will not the person who will work on after project completes, but there always will be someone else .

So for the sake of code maintainability and unforeseen scenarios, you should never go for Generic Repositories.

First they will be fun and very less code, so much inheritance and polymorphism that you begin to think this is it. Now you don’t have to do the hard work, everything is managed now. Thanks to the people who invented it, But no, it will be out of hand very soon.

So Generic Repositories is BIG NOOOO.



Categories
Uncategorized

HTML Template with JQuery


Yes, you heard right, there are tons of new JS frameworks which are more powerful with this stuff like react native, angular, backbone, knockout, ember and the list goes on.

But our old favorite JQuery and it’s tons of plugins still has almost like 80% of the Internet market share.

Often you need to perform ajax calls and load dynamic data into your html from Ajax calls. If you are like the most people, you’ve probably done with declaring html markup in javascript variables and then append it. like

<div>
    <ul id="result">
    </ul>
</div>
$.ajax({
url:'http://example.com',
type:'get',
success:function(data){
var li = '<li>'this is my data'+data.value</li>';
}
})

Yes its very easy and manageable if you just have to print these li but what if you need to display address, names, telephone numbers of users in a bootstrap cards layout. You will write the whole card layout in your JS, e.g.

var htmlTemplate = '
'<div class="card">'+
  '<div class="card-header">'+
    +data.businessName+
  '</div>'+
  '<div class="card-body">'+
   ' <div class="telephone">'+
      +data.Telephone+
    '</div>'+
    '<div class="address">'+
      +data.address+
    '</div>'+
  '</div>'+
'</div>';

This code is beginning to smell now. And soon as the requirements raises, code will become unmanageable, unreadable, and prone to errors and bugs. What if I tell you there is a cleaner and more manageable way to do that.

So here are the steps to do that:

  • Create the html template at bottom of your page like this:
<div class="card">
  <div class="card-header">
  {businessName}
  </div>
  <div class="card-body">
    <div class="telephone">
	{Telephone}
    </div>
    <div class="address">
	{address}
    </div>
  </div>
</div>

Now set this template block’s visiblity to none.

  • Now add this html based template visibility to none
  • Get that whole template element with jquery
  • Clone the element with jquery’s clone()
  • replace the variables in {} with your data
  • append the final element to the content area of your html.



Categories
Uncategorized

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!