OOP Design & Analysis: BookStore Management Project — Part I

Sera Ng.
Tech Training Space
5 min readOct 19, 2020

Learn OOP design and analysis by building a project called BookStore management

Part I: Analysis and Design

Skills: Object-Oriented Programming (OOP), Array, ArrayList,

Language: Java — JDK 8

IDE: Netbeans 8 (any other IDEs will work)

Application type: Console

Development Operating System: Windows 10

Description:

In this project, I’ll walk you through OOP concepts and how to apply these concepts to build a program.

Throughout this project, you’ll also learn other fundamental and must-known techniques:

  • Storing data in an array
  • OOP Design & Analysis
  • Collections Framework

Prerequisite

In order to have the best results, learners should already have:

Very basic Java skills such as variables, methods, data types…

Scenario

The BookTiger company runs a bookstore and they need software to manage their books.

Each book comprises of the price, the ISBN, and the published year.

The new software should support the following features:

  • Add a new book: a new book with all details should be added to the system. Each book should have a unique ISBN
  • Update an existing book: an existing book should be able to be updated based on its ISBN
  • Remove an existing book: a book can be removed from the system based on its ISBN
  • Print a list of books

Task 1: Requirement analysis

From the requirements, we can break down into data needed to be stored and functional requirements as follows:

Data to store:

  • Each book contains: price, ISBN, published year
  • List of books

Program Features (Functional requirements):

  • Add new book with a unique ISBN
  • Update a book
  • Remove a book
  • Print all books

Task 2: Define constraints and data structure

There is one constraint: each book should have a unique ISBN. That means every time a new book is added to the system, we need to check if that ISBN has already existed.

Since the system needs to store a list of books, we will use an Array for this job.

Task 3: Exploring the Object-Oriented Paradigm (OOP)

Before getting into implementing the program, let’s discuss some of the fundamental concepts in OOP.

A first concept is an object. What are objects?

Objects are anything in our real world:

Each object has states (data/attributes) and behaviors. For instance:

A software object is similar to a real-world object, in which:

  • States: are stored in fields, which we usually called variables
  • Behaviors: are exposed through methods

How we build a program using OOP?

The fundamental approach in OOP is that: to build a program, we first create necessary objects, then we integrate these objects to form a program. A program can also be considered a large object.

This methodology is similar to the way we build a physical computer:

If multiple objects share the same structure of attributes and behaviors, we can form a Template so that we can create more objects with the same structure of attributes and behaviors with different values. In OOP terms, Template is called Class

So, a class is a blueprint, or prototype, or template from which objects are created

As you can see, creating a program using OOP methodology is pretty much of creating required objects and integrate those objects altogether.

In order to facilitate the integrating process (which means components should be easy to assemble), each object (RAM, CPU…) needs to be as Abstract as possible. Which means only necessary information is exposed to the outside world, other details should be hidden. The process of hiding information is called Encapsulation.

But if an object is encapsulated, how its details are exposed to the outside world?

There are two main ways to expose an object’s details to the outside world:

If the purpose of exposing data is to connect to other objects, then, we can expose via Interface:

If the purpose of exposing data is to retrieve data or to change data of the object, then we can expose it via Getter and Setter.

  • Getter is for retrieving data
  • Setter is for changing/updating data inside the object.

Interface is also the way to achieve Polymorphism. Polymorphism refers to the ability to treat objects differently depending on their data type or class, as illustrated below:

Polymorphism is the way to extend our program without (or limited) compromising the existing data or code.

[Device image sources: Google]

Task 4: Class Design

Once you got the fundamental concepts, let’s design our application

Based on the requirements, we can define the following classes with related data and behaviors (methods)

Here is the visual diagram of classes and interface that form our main features:

[End of Part I]

--

--