Variables are used to store data. There are two types of variables. They are primitive and reference. Primitives hold fundamental values including integers, booleans, and floating-point numbers. Object references hold references to objects. variables must have a type and name. The eight primitive types are:

An object reference variable holds bits that represent a way to access an object. It doesn’t hold the object itself, but it holds something like an address. a primitive variable is full of bits representing the actual value of the variable, an object reference variable is full of bits representing a way to get to the object.

References

[1] Sierra, K., & Bates, B. (2005). Head First Java, 2nd Edition (2nd ed.). O’Reilly Media.

--

--

A Memento Pattern says that “to restore the state of an object to its previous state”. But it must do this without violating Encapsulation. Such case is useful in case of error or failure.

Benefits:
• It preserves encapsulation boundaries.
• It simplifies the originator.

Usage:
• It is used in Undo and Redo operations in most software.
• It is also used in database transactions.

Structure

Implementation example

Output

--

--

Builder Pattern says that separate the construction of a complex object from its representation so that the same construction process can create different representations.it means that construct a complex object from simple objects using step-by-step approach.

The main advantages of Builder Pattern are as follows:
• It provides clear separation between the construction and representation of an object.
• It provides better control over construction process.
• It supports to change the internal representation of objects.

When we create objects with multiple combinations, we need to create multiple constructors or telescoping constructors. This builder design pattern is used to avoid this complexity of creating multiple constructors.

Structure

Implementation example

Output

--

--