Application Development Principles and JavaScript

Mishan Kavindu Perera
6 min readFeb 26, 2022

--

In the software development industry, application frameworks are utilized by industry standards. The industry should adhere to certain principles to design software properly. Those principles are shown below.

  • S.O.L.I.D.
  • Approaching the solution
  • Implementing the solution
  • Practices

1. S.O.L.I.D.

When designing software, the S.O.L.I.D. Object-oriented principles should be followed.

  • Single responsibility
  • Open-close
  • Liskov substitution
  • Interface segregation
  • Dependency inversion

a. Single responsibility

A class should all have one responsibility, according to this principle. It should also only have one reason to alter.

b. Open-close

Classes should be open for extension but closed for modification. Thereby, we avoid altering old code and perhaps introducing new issues into an otherwise stable program.

c. Liskov substitution

This implies that each subclass should substitute for its parent class. Unimplemented methods should not be present in a child class. After overriding methods in the base class, the child class should not give them a different meaning.

d. Interface segregation

This means more extensive interfaces should be divided into smaller ones. By doing so, we can ensure that implementing classes are only concerned with the appropriate methods. They are referred to as “fat interfaces”.

e. Dependency inversion

This specifies that the high-level module should rely on abstractions instead of the low-level module.

2. Approaching the solution

We aim to discover a technical solution for a business challenge in software engineering. The various options for achieving that goal are shown below.

  • KISS
  • Think about the problem thoroughly.
  • Divide and conquer
  • Learn from the mistakes
  • Keep in mind why software exists
  • Always keep in mind that you are not the user

a. KISS

Maintain a straightforward and understandable approach. Make your solution simple, not complicated.

b. Consider the problem all the way through

Make sure you properly comprehend the problem you’re going to fix. Before creating the solution, make sure that any confusing parts are clarified.

c. Divide and conquer

Break the problem down into smaller pieces. Make it manageable and straightforward to comprehend. Try to strike the ideal balance between priority and clarity.

d. Learn from the mistakes

Accept the change. Always try to anticipate as many changes as possible.

e. Keep in mind why software exists

Keep in mind why this software exists in the first place. If you lose sight of the big picture, you can get on the wrong track.

f. Always keep in mind that you are not the user

The end-user does not have the same technical capabilities as the program creator. User-friendliness and experience are important factors to consider when developing software.

3. Implementing the solution

There are several guidelines to remember when executing the designed solution. Those guidelines are shown below.

  • YAGNI
  • DRY
  • Embrace abstraction
  • D.R.I.T.W.
  • Write code that is great for a single task
  • Debugging is more complicated than programming
  • Kaizen

a. YAGNI

YAGNI is an acronym for “You ain’t gonna need it”. Write the code that isn’t useful right now, but you think it will be helpful in the future.

b. DRY

DRY is an acronym for “Don’t repeat yourself”. As much as feasible, code should be generalized and reusable.

c. Embrace abstraction

Make sure your system works correctly, even if you don’t know the implementation specifics of each component.

d. DRITW

DRITW is an acronym for “Don’t reinvent the wheel”. It’s possible that someone else has already solved that problem. Make the most of it.

e. Write code that is great for a single task

A single piece of code that does one thing and does it well.

f. Debugging is more complicated than programming

As much as possible, make the writing code readable.

g. Kaizen

Kaizen refers to “Leave it better than when you found it”. Bugs occur during the writing of the code. Then, it should be fixed, not just the bug but also the code surrounding it.

4. Practices

Practices are standards or principles that we should adhere to when writing code. Industry-wide, these approaches are regarded as best practices for software engineering.

· Unit Testing

· Code quality

· Code review

· Version controlling

· Continuous integration

a. Unit testing

Unit testing is a small code that checks certain aspects of your main program. A unit can be anything from a class to a function to a module to an API. Allows the developer to freely modify or improve the code while also ensuring that it does not damage anything by running unit tests. For developers, there is a verification mechanism. Early detection of integration difficulties is essential.

b. Code quality

Code quality is reduced by code complexity, huge methods and classes, meaningless identifiers, code duplication, and many method arguments. The code should be legible and straightforward to comprehend. Use tools to check the code quality regularly. Improve the code’s performance.

c. Code review

Find the best strategy to solve the problem and improve your performance by review. The goal is to enhance the code instead of criticizing the developer. Code reviews can be done in various ways, including peer reviews, lead reviews, and pair programming.

d. Version controlling

Version control should be applied to all code. Allow developers to update and improve the code freely. Allow several developers to work on the same codebase simultaneously. Remove the code base’s single point of failure. To keep the code base up to date, use various branch tags.

e. Continuous integration

Developers must check their code to a shared repository several times a day. This allows developers to spot problems early and fix them quickly.

JavaScript

A single thread is used to run JavaScript programs. As a result, JavaScript is classified as a single-threaded programming language. JavaScript does not wait for I/O operations to complete before continuing with the program’s execution. Non-blocking, I/O is what it’s called. Because of the NIO nature of JavaScript, it is asynchronous. Both OOP and functional programming are supported by JavaScript. Asynchronous operations in JavaScript are managed via an eventing mechanism.

function getName(){
return "Hello World!"
}
const print = function (){
console.log(getName())
}
print()
//Output: Hello World!

Classes and objects in JavaScript

Static methods and variables are supported in JavaScript. A constructor function is used with the ‘new’ key keyword when constructing an object in JavaScript. When a function is used with the ‘new’ keyword, it becomes a Class. Object literals (‘{}’) are another technique to create an object. These are referred to as singleton objects.

function Country(name){
this.name = name;
}

const country = new Country("Sri Lanka")
console.log(country.name)
//Output: Sri Lankaconst Animal={
name: 'Dog',
getName : function () {
return this.name;
}
}
console.log(Animal.name)
//Output: Dog

Prototypes

JavaScript functions reference another object called prototype. It’s similar to how classes are defined in other languages. It’s just another instance of an object. A prototype object is utilized in JavaScript when creating objects, inheriting classes, and adding methods to a JavaScript class. Because of JavaScript’s flexibility, there are numerous ways to build and expand classes. A constructor function is a type of function used to make objects. A prototype is an object instance from which another object is constructed. The inherited properties of an object come from the object ‘__proto__’. The prototype of a function is used to pass properties to an instance of an object.

function Animal(name){
this.name = name;
this.getName = function (){
return this.name;
}
}

const dog = new Animal('Dog')
const cat = new Animal('Cat')
console.log(dog.getName === cat.getName);
console.log(Animal.prototype === dog.__proto__);

/*output: false
true */
Diagram of the process

‘this’ in JavaScript

The word ‘this’ in the context of an object refers to the object itself. When a function utilizing the ‘this’ keyword is handed to another object, ‘this’ refers to that object instead of the original object where the function was declared. In JavaScript, the ‘this’ keyword behaves differently than it does in other languages.

--

--

Mishan Kavindu Perera

Software Engineering Undergraduate of Sri Lanka Institute of Information Technology