Skip to main content

Featured

SQL vs NoSQL.

SQL vs NoSQL.   By  Jeewantha Hiddalarachchi. In this tutorial, I going to discuss the difference between SQL and NoSQL databases. Let's start with a brief explanation about SQL and NoSQL. What is SQL? Structured Query language (SQL) is the standard language to communicate and deal with relational databases.  A relational database is a form of tables. Basically, we use SQL to insert, search, update and delete database records but it helps users to do lots of things like optimizing and maintenance of databases. SQL databases are table-based databases and there are vertically scalable. Not only that but also SQL has a predefined schema and always requires specialized DB hardware for better performance. Examples SQL databases -   MySQL  Microsoft SQL Server Oracle Sybase What is NoSQL? NoSQL is a non-relational Database Management System. And also NoSQL not like SQL because it does not require a fixed schema, avoids joins. It is mainly focused on scaling, fast queries, allowing for fr

Basic Object Oriented Programming (OOP) Concepts.

Basic Object-Oriented Programming (OOP) Concepts.

by Jeewantha Hiddalarachchi.


Introduction of OOP concepts.

First Let's get some idea about Object-Oriented Programming. What is Object-Oriented Programming?. Object-Oriented Programming is about creating objects with including data and methods or we can say Object-Oriented Programming is a methodology that helps to design programs using class and objects. It different from Procedural programming because Procedural programming is about performing operations on data by writing procedures or methods.

We can line up some advantages of OOP over procedural programming as bellow:

  • faster and easier to execute
  • provides a clear structure for the programs
  • helps to keep the Java code DRY "Don't Repeat Yourself", and makes the code easier to maintain, modify and debug
  • makes it possible to create full reusable applications with less code and shorter development time
OOP concepts mainly help to do software developments and maintenances easily. There are some OOP concepts like :

  1. Object
  2. Class
  3. Inheritance
  4. Polymorphism
  5. Abstraction
  6. Encapsulation

Object-Oriented Programming system (OOPs).


1. Object.

The object is a physical or a logical real-world entity that has a state and behavior. and also we can define an object as an instance of a class. The object needs some space in memory for storing the object's address. 

Example: Tablet, Pen, Watch, etc.

2. Class.

A class is a collection of objects and also we can define a class as a blueprint because it defines the structure to create an object. But class doesn't take any space in memory.

3. Inheritance

Inheritance is an important theory in OOP and it is a mechanism in which one object acquires all the properties and behaviors of its parent class. Not only that it helps to reuse the code. From this inheritance theory, you can create new classes by using existing classes and it can use to conclude runtime polymorphism. 

Inheritance represents the parent-child relationship (IS-A or HAS-A relationship). 

4. Polymorphism

Polymorphism is a concept and It can perform a single action in many ways. This concept mostly related to Inheritance and there are two types of Polymorphism like static and dynamic. Static polymorphism use for overloading methods and Dynamic polymorphism use for overriding methods. 

Therefore we can write a code for a superclass, it will also work with as well as on its subclasses. 

For example, assume a parent class called Animal and it has a method called sound(). There are some subclasses like Dog, Cat, Elephant, Duck, etc. Therefore sound() automatically comes to the child classes also because of the effect of Inheritance and they also have their own implementations of sound. 

Another example by using a class diagram:

5. Abstraction

Abstraction is a process which use to hide the implementation details from users and showing only functionality. In simply, it shows only essential things to the user. 

Abstraction can be achieved with abstract classes or interfaces.

Let get more idea about abstraction by using an example.

Assume making coffee using a coffee machine. You know what ingredients want to input into the coffee machine and the coffee machine operation. But you don't need to know the internal working process of the coffee machine. Therefore coffee machine acts like abstraction.

You can see another example in this picture.

6. Encapsulation

Encapsulation is used to bind the code and the data together into a single unit. Therefore it also helps to hide sensitive data from users. we can get a medicine capsule as an example for this Encapsulation theory because various medicine ingredients are containing in a capsule.


And also we can get Java Bean as an example for the fully encapsulated class which create from all data members classes as private classes. To access or update those variables or attributes in a private class, we use Getters (get method) and Setters (set method).
  • Getters (get method) - returns the variable value.
  • Setters (set method) - sets the value.

Advantages of Encapsulation.
  1. Make class read-only or write-only.
  2. Control over the data.
  3. Data hiding.
  4. Easy to unit test.
  5. Easy and fast to create an encapsulated classes.
Summary

We discussed Basic Object-Oriented Programming concepts. And also know how they are helping your whole code implementation. 

Thank you very much for reading and I hope you have a better idea about this topic...😊 .

Comments

Popular Posts