Overview

Arrow functions are similar to Java and Pythons lambda function. Arrow functions can be used instead of Javascript traditional function definition. Arrow functions are more compact but there are some limitations:

  • No bindings to this or super so it should not be used inside object if they are to be methods
  • No access to arguments or new.target
  • Should not be used with call, apply and bind methods because they rely on a scope or the current context where it is being executed
  • Cannot be used as a constructor
  • Cannot use yield in its definition
Image for post
Image for post
Photo by Nick Fewings on Unsplash

Implementation

Instead of using the function key word you would wrap the arguments in parenthesis as usual than the arrow, =>, followed by the definition. If the there is only one argument you can ignore the parenthesis. Similarly if the definition only has one line you can ignore the curly braces as well the return keyword because it is implied. You can assign the arrow function to a variable as well. …

Lambda is a short block of code that is a function do not have a name

Overview

Lambda was added to Java in version 8. Similar to Python lambda is a short block of code that is a function do not have a name. Like functions they can take in arguments and returns a value. Unlike Pythons lambda Java has its own way of using lambda. Like in Python lambda functions are typically used in higher order functions or functions that take in another function as an argument.

Image for post
Image for post
Photo by Markus Spiske on Unsplash

Implementation

To use lambda you start by declaring the argument separated by -> then the function definition.

// argument -> definition
x -> System.out.println(x)

If the lambda function takes in more than 1 argument or not argument it needs a parenthesis. …

Overview

Lambda is a single line function with no name that can have multiple arguments but only one expression. This is useful for writing functions that will only be run once.

Image for post
Image for post
https://devclass.com/wp-content/uploads/2018/10/lambda.jpeg

Implementation

Normal Implementation

def add(x, y):
return x + y

Lambda Implementation

lambda a, b : a +b

As you can see in order to declare a function as a lambda function you need to use the lambda keyword. What follows after the lambda keyword are the arguments of the function. Then the colon symbol separates the argument from the definition.

Assignment

You can save the lambda function by setting a variable equal to the lambda function. …

Overview

Normally we use numbers from 0–9 which a base 10 system called decimal. Binary is a number system using base 2 system. This means it just uses 2 numbers 0 and 1. Computers use binary to store data and each bit is represented by a 1 or 0. Each bit is grouped in 8 bits which represents a byte. Hexadecimal uses base 16 which is easier to represent 8 bits using only 2 digits instead of binaries 8.

Image for post
Image for post
Photo by Markus Spiske on Unsplash

Binary and Decimal

Each digit in a decimal represents a power of 2. So starting from the right to left is 1, 2, 4, 8, 16 etc. When converting binary to decimal you figure out what digit represents what power of 2 and if it has a 1 add the power of 2 together. For example: 10101. From right to left the 1’s represent 1, 4, and 16 so to convert we add those number and we get 21. …

Overview

As the name suggests MVC design patterns involves 3 parts:

  • Model — The object that contains the data. It should contain no logic to display data.
  • View — Presents the data to the user. It should only have the logic to display the data and not any logic to manipulate it.
  • Controller — Controls the data flow between the model and view keeping the two of them separate. The view triggers events that cause the controller to change the model.
Image for post
Image for post
Photo by Halacious on Unsplash

Implementation

Model

// Employee.java
public class Employee {
private int id;
private String name;

public String getId() {
return rollNo;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name …

Overview

The main idea for the facade design is hiding the complexities of the application. The user would use an interface/facade instead to access any methods.

Image for post
Image for post
Photo by Daniel von Appen on Unsplash

Implementation

Interface

// Animal.java
public interface Animal {
void species();
}

Interface for concrete class.

Class Implementation

// Dog.java
public class Dog implements Animal {
@Override
public void species() {
System.out.println("Dog");
}
}

Interface implementations.

// Cat.java
public class Cat implements Animal {
@Override
public void species() {
System.out.println("Cat");
}
}
// Bird.java
public class Bird implements Animal {
@Override
public void species() {
System.out.println("Bird");
}
}

Facade

// AnimalMaker.java
public class AnimalMaker {
private Animal dog;
private Animal cat;
private Animal bird;

public AnimalMaker() {
dog = new Dog();
cat = new Cat();
bird = new Bird();
}

public void dogSpecies(){
dog.species();
}
public void catSpecies(){
cat.species();
}
public void birdSpecies(){
bird.species(); …

Overview

Data Access Object or DAO is used to separate used low level from high level data access api. There are 3 parts to DAO:

  • Data Access Object Interface — The interface contains the operations that can be performed on the models.
  • Data Access Object Class — The class implements the interface. The class is what retrieves the data from the database or wherever the data is stored.
  • Model Object — The object is a simple Plain Old Java Object(POJO) with getters and setters to store data. To access the object you would use the DAO class.
Image for post
Image for post
Photo by Lukas Blazek on Unsplash

Implementation

Model Object

// Employee.java
public class Employee {
private String name;
private int id;

Employee(String name, int id){
this.name = name;
this.species = species;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public int getId() {
return this.id;
}

public void setId(int id) {
this.id …

Overview

The factory pattern is a popular design pattern in Java because it is one of the best way to create an object. The general idea is allowing the user to create objects without exposing the logic behind it. Instead an interface is provided for the user to know what method to be called to create the object.

Image for post
Image for post
Photo by Science in HD on Unsplash

Implementation

Interface

Animal.java

public interface Animal {
void species();
}

Implement Interface

Dog.java

public class Dog implements Animal {
@Override
public void species() {
System.out.println("It's a dog.");
}
}

Cat.java

public class Cat implements Animal {
@Override
public void species() {
System.out.println("It's a cat.");
}
}

Bird.java

public class Bird implements Animal {
@Override
public void species() {
System.out.println("It's a bird."); …

Overview

Singleton is one of the simplest design pattern and it falls under creational pattern. The idea of singleton is creating a class that only creates one object that will always be used. The class will provide a method to access the same object without having to instantiate it.

Image for post
Image for post
https://www.tutorialspoint.com/design_pattern/singleton_pattern.htm

Implementation

The following code is in Java.

public class Singleton {
// It is static so it will be the same instance
// It is private so it will only be accessible through the getter
// Constructor is called to instantiate a new instance
private static Singleton instance = new Singleton();
// Constructor is private so no new instances can be instantiated
private…

Overview

Flux is used at Facebook for their front end web application. It is more of a pattern than a framework. The three main parts of Flux are the action, dispatcher and the store. The data flow is unidirectional which makes debugging easier. Redux is a library that uses Flux.

Image for post
Image for post

Action

The action is what is called when a user interacts with the application. For example, if you want to add a new task to a to do list you would create an action for that. …

About

Daniel Liu

Hi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store