Must know principles for an Object Oriented Programmer and an introduction for JavaScript

Kevinwijesooriya
6 min readFeb 26, 2022

Creating software is a difficult process. To keep a clear mind, it is critical to organize your workload efficiently. When programming, applying these principles will greatly assist you in breaking down and approaching a problem solution. This article will teach you how to approach a problem, how to implement a solution, and what best practices to follow.

1. S.O.L.I.D

Single responsibility

A class should have a single purpose

Open-close

Objects or entities should be open to expansion but not to modification.

Liskov substitution

Every subclass/derived class should be able to replace its parent/base class.

Interface segregation

Clients should not be forced to use methods that they do not prefer.

Dependency inversion

Higher level modules should not rely on lower level modules, but rather on abstractions.

2. Approaching the solution

Think throughout the problem

Think through the problem before approaching the solution or even starting to think about it. Make certain that you completely understand the problem you intend to solve. Before designing the solution, make sure to clear up any confusion. There are no stupid questions, so don’t be afraid to ask them.

Divide and conquer

Now, break the problem down into smaller parts. Make it manageable and simple to understand. Attempt to strike the ideal balance between priority and clarity.

KISS

Keep it simple and stupid. Make your solution as simple as possible. Avoid overthinking or overengineering.

Learn, especially from mistakes

Accept the change. Always try to anticipate changes as much as possible. Do not overengineer it, but leave room for expansion.

Always remember why software exists

Remember why the software exists in the first place. A failure to see the big picture may lead to a wrong turn.

Remember that you are not the user

You must comprehend the end-user is not as technically capable as you are. Don’t assume that the user knows everything. What matters most is user friendliness and user experience.

3. Implementing the solution

YAGNI

(You ain’t gonna need it)

Do not write code that is currently useless but you believe will be useful in the future because the future is always changing. This is a complete waste of time. Write only the code you require for the time being.

DRY

(Don’t repeat yourself)

Always re-use code you’ve written. Make your code as general and reusable as possible.

Embrace abstraction

Make sure your system works properly even if you don’t know the implementation details of each component part. The user class should be able to authenticate a user without knowing where to obtain the user’s username and password.

DRITW

(Don’t reinvent the wheel)

If someone else has already solved the same issue. Make sure to take advantage of it.

Write code that does one thing well

Create simple code to perform a specific task. Do not try to do everything with a single line of code.

Debugging is harder than writing code

Make certain that your code is written in a readable manner.

Kaizen

Do not try to fix individual lines of code; instead, try to solve the entire problem.

4. Practices

Unit testing

Unit testing is a testing technique in which individual modules are tested by the developer to see if there are any problems. It is concerned with the standalone modules’ functional correctness. The primary goal is to isolate each component of the system in order to identify, analyze, and correct any flaws.

Code Quality

Code that is easy to maintain Code quality is essential. The code should be readable and simple to understand. Engineering best practices, as well as language and domain best practices, should be followed when writing code. Using tools, analyze the code quality on a regular basis. Determine any potential erroneous scenarios. Enhance the code’s performance.

Code review

The most effective way to improve code quality. The goal is to improve the code rather than to criticize the developer. Improve performance, figure out the best way to solve the problem; having more than four eyes on the code is beneficial. Code reviews can be done in a variety of ways, including peer reviews, lead reviews, and pair programming.

Version controlling

The practice of tracking and managing changes to software code is known as version control, also known as source control. Version control systems (VCS) are software tools that assist software development teams in managing changes to source code over time. Version control systems assist software teams in working faster and smarter as development environments have accelerated. They are especially beneficial to DevOps teams because they help to reduce development time and increase the number of successful deployments.

Continuous integration

Continuous integration is a method of development. Developers must check-in code to a shared repository multiple times per day. An automated build verifies each check. This enables developers to detect problems early and fix them quickly.

That is a summary of the main basic principles that you should adhere to as an Object Oriented Programmer. Now we’ll take a look at one of the industry-leading framework JavaScript.

JavaScript

Introduction

JavaScript is a scripting language that is lightweight, cross-platform, and interpreted. It is well-known for web page development, but it is also used in many non-browser environments. JavaScript can be used for both client-side and server-side development. JavaScript includes a standard object library, such as Array, Date, and Math, as well as a core set of language elements such as operators, control structures, and statements.

Classes, objects and prototype

Classes serve as a starting point for the creation of objects. They encapsulate data with code that allows them to work with it. Classes in JS are prototype-based, but they also have some syntax and semantics that are not shared with ES5 class-like semantics.

Class declaration

Objects are the most important data type in JavaScript and serve as the foundation for modern JavaScript. These objects differ from JavaScript’s primitive data-types (Number, String, Boolean, null, undefined, and symbol) in that, whereas these primitive data-types all store a single value, these objects store multiple values (depending on their types).

How ‘this’ acts

In most cases, the value of this is determined by how a function is called (runtime binding). It cannot be set by assignment during execution, and it may be different each time the function is called. ES5 introduced the bind() method to set the value of a function’s this regardless of how it’s called, and ES2015 introduced arrow functions that don’t provide their own this binding.

Strict notation

Strict mode modifies the normal JavaScript semantics in several ways:

Some JavaScript silent errors are eliminated by converting them to throw errors. Corrects errors that make it difficult for JavaScript engines to optimize: Sometimes strict mode code can be made to run faster than identical non-strict mode code. Some syntax that is likely to be defined in future versions of ECMAScript is prohibited.

Function closure

A closure is a function that has been bundled (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure allows you to access the scope of an outer function from an inner function. Closures are created in JavaScript every time a function is created, at function creation time.

Callbacks and promises

A process is told to call another function when the result is ready in order to perform asynchronous processing rather than waiting for a function to complete its execution. The callback is the name given to this “other function.” Any asynchronous function accepts it as an argument.

A Promise is a JavaScript object with a value that may not be available at the moment when the code line executes. These values are resolved at some point in the future. It allows you to write asynchronous code more synchronously.

So that brings us to the end of my blog. I believe readers will find it interesting and useful to read my blog.

Wijesooriya W A D J K D

--

--