Me to Google: “How to build a Web App 👀”

Matts Makhura
6 min readApr 27, 2021

Google to Me: “ Sort out your basics fam 🤨”.

Thobela Lefase! Lately, I have been finding open-source frameworks such as Spring Boot very interesting. You might be asking yourself “Spring Boot” is that a car boot that springs at a car boot sale or is that a new song by the legendary Thebe (abuti bula boot , bare bulabot …) 😅 ?

Photo by Roberto Pansolli on Unsplash

Unfortunately, that’s not the case. Spring Boot is a Java-based framework used to create one or more micro services that are used to build “stand-alone and production-ready spring applications” 🤯.

Ok, to some of you reading this — that definition might be super technical. To simplify this let’s define the word framework. Framework or (“Tlhako ya Tlhamo’’ in Sesotho sa Leboa) in the world of tech nerds , is a reusable basic design structure, consisting of different programming building blocks that assists in building applications.

According to Google popular companies such as Udemy, trivago, FNB and etc. make use of this useful open-source Spring Boot framework to build their platforms and perform different use cases with it.

When I first started playing around with the Spring Boot framework I struggled to understand some concepts because well I thought I could just do it like a Nike Shoe (😅 I know that was very dry hey🤓 — but like I am serious I thought I would just understand it); ergo, in my frustration, I decided to go back to the basics. The basics of what abstraction, inheritance means before I could continue on with my Spring Boot journey.

Data Abstraction

Ahh-re tho-meng ka kgo explain-na (let’s start with explaining) Data Abstraction. You can think of abstraction as a basic abstract you would write for your final year project report. The main aim of that abstract is not to detail out every single aspect of that report but rather to highlight what you think is important to the reader.

Another relatable example of abstraction is your smartphone — most of us know how to operate smartphones and even know how to optimize them to take great photos and videos. However, not many of us care about the intricate inner workings and engineering of how a touch screen is wired up and the engineering involved in converting what the lenses of your camera see into high-quality pixels. We “abstractly” just know how to use our smartphones.

Abstract Classes

Abstract Class High Level Diagram

Abstract classes can be defined as classes that are declared “abstract” as seen in the JAVA code below and cannot be called directly (instantiated) in the main program but rather through Subclasses in the main program. Abstract classes are made up of :

  1. Fields ( properties of the class)
  2. Non-abstract Methods( behaviors of the class — they include “{ what the method does }”)
  3. Abstract Methods (so these are methods that are only implemented in subclasses — they don’t have “{ }”)
// Example of Parent Abstract Class: 
public abstract class PapaObject {
// declare fields
String nose;
String eyes;
String skinColor;
// declare nonabstract methods
public void commonValue(){
System.out.println("I have Respect just like Papa");
}
// declare abstract method
public abstract void inheritedValue();
}
// Example of Child Subclass:
class ChildOne extends PapaObject{
// previously declared abstract method
public abstract void inheritedValue(){
System.out.println("I am strong and kind just like Papa");
}
}
class ChildTwo extends PapaObject{
// previously declared abstract method
public abstract void inheritedValue(){
System.out.println("I am strong and intelligent just like Papa");
}
}

You will notice above that the Subclass uses the keyword “ extends “ in order to inherit from the PapaObject class.

Interfaces

Interfaces High Level Diagram

An Interface in Java is like a full blueprint of what other classes can or cannot do. Interfaces are similar to Abstract classes described previously above with one of the differences being that Interfaces are only made up of the following:

  1. Abstract Methods (so these are methods that are only implemented in subclasses — they don’t have “{ }”)
  2. Default Methods of implementation (Java 8 and above — declared using the keyword “default” )

This makes Interfaces fully abstract. A subclass can access interfaces using the keyword “implements”. Think of it this way since Interfaces don’t have methods that are implemented; we are now giving that particular Subclass the right to “implement” those methods as shown below in the code :

//Example of Parent Interface: interface PapaObject { 
// declare abstract fields
String nose;
String eyes;
String skinColor;
// declare abstract method
public abstract void inheritedValue();
public void simmilarInterests() } //Example of Child Subclasses:
class ChildOne implements PapaObject{
// previously declared abstract method
public abstract void inheritedValue(){
System.out.println("I am strong and kind just like Papa");
}
public abstract void simmilarInterests(){
System.out.println("I like farming just like Papa");
}
}
class ChildTwo implements PapaObject{
// previously declared abstract method
public abstract void inheritedValue(){
System.out.println("I am strong and intelligent just like Papa");
}
public abstract void simmilarInterests(){
System.out.println("I like reading just like Papa");
}
}

More examples on Abstract classes and Interfaces can be found here.

One other similarity that Interfaces share with Abstract Classes is that they too cannot be instantiated- they can only be implemented by subclasses or extended by other interfaces. Additionally, since interfaces don’t have non-abstract methods that means you also cannot declare constructors in interfaces.

Lastly, Interfaces require us to override all its methods with the same method signatures upon implementation because by default all the methods are abstract or public. There are cases where you have a method with visibility that is not public in the interfaces. In such cases, we cannot override those methods.

Why is this all-important to Spring Boot Application Developers?

The most common and simplest way to build web applications is through layers as shown below:

The Data Layer is usually composed of the following :

  1. Entity ( Normal Java Bean Classes — with getters and setters — that define the tables in data source )
  2. Repository ( Interface that extends for -example- the JpaRepository)

The Business Layer is usually composed of the following :

  1. Domain (Normal Java Bean Classes — defines domain to be used in service block)
  2. Service (Normal Spring Bean Classes — that wire up all the relevant repositories and domains to perform a service)

The Web Layer is usually composed of the following :

To see a practical example of this check out my GitHub here. From the above definition, we can see that parts of the business layer are composed of Interfaces and basic abstraction. This principle allows us to hide certain parts of our web application from other layers. For example, the business layer can persist(ask for) data in the data layer through the repository (storage we created).

In conclusion, engineering a web application requires you to understand the basics. That is the basics of Abstractions -which we covered in this article, Collections, Lambda Expression, ArrayList and so much more. Once you master this or have built some sort of foundation it’s always easy to experience multiple orgasms of light bulb moments as you do more Web Dev Tutorials.

References:

  1. https://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html
  2. https://www.springboottutorial.com/software-design-what-is-abstraction
  3. https://www.w3schools.com/java/java_abstract.asp

Published By

Originally published at https://www.linkedin.com.

--

--

Matts Makhura

If I would compare myself to a rock it would be a “Diamond” because it’s flaws is what makes so specials and impactful. I am here to learn and grow.