Skip to content

YuriiJavaDev/JavaBasics_Task_453_V0.2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Digital Library Catalog: Record Refactoring (JavaBasics_Task_453_V0.2)

📖 Description

In modern Java development (v16+), Records have become the standard for simple data transfer objects (DTOs). This project refactors the previous library catalog to use a Record instead of a traditional class. By doing so, we eliminate boilerplate code such as explicit constructors and getters. The project demonstrates how records seamlessly integrate with the Java Collections Framework, providing a cleaner and more readable way to manage a "shelf" of immutable book entries.

📋 Requirements Compliance

  • Boilerplate Reduction: Replaced a 20-line class with a 1-line record definition.
  • Immutability by Design: Ensured that book titles and authors cannot be modified after creation, increasing data safety.
  • Modern Syntax: Utilized record-style accessors (e.g., book.title() instead of book.getTitle()).
  • Clean Code Evolution: Applied the latest Java features to make the codebase more maintainable and expressive.

🚀 Architectural Stack

  • Java 16+ (Records, Collections Framework)

🏗️ Implementation Details

  • Book: A record serving as an immutable data unit for library entries.
  • LibraryCatalogApp: The main execution class utilizing the refactored record model.

📋 Expected result

Title: The Master and Margarita, Author: Mikhail Bulgakov
Title: 1984, Author: George Orwell

💻 Code Example

Project Structure:

JavaBasics_Task_453_V0.2/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── LibraryCatalogApp.java
│                 └── library/
│                     └── models/
│                         └── Book.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.library.models.Book;
import java.util.ArrayList;
import java.util.List;

public class LibraryCatalogApp {

    public static void main(String[] args) {

        List<Book> catalog = new ArrayList<>();

        catalog.add(new Book("The Master and Margarita", "Mikhail Bulgakov"));
        catalog.add(new Book("1984", "George Orwell"));

        for (Book book : catalog) {
            System.out.println("Title: " + book.title() + ", Author: " + book.author());
        }
    }
}
package com.yurii.pavlenko.library.models;

public record Book(String title, String author) {
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_453_V0.2 Digital Library: refactoring the Book model to a Java Record for concise, immutable data handling and simplified collection management. 120526_0824

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages