Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Дублювання коду #2

Open
ipz234 opened this issue Feb 4, 2025 · 0 comments
Open

Дублювання коду #2

ipz234 opened this issue Feb 4, 2025 · 0 comments

Comments

@ipz234
Copy link
Owner

ipz234 commented Feb 4, 2025

Code:

public void ShowBooks()
{
    for (int i = 0; i < books.Count; i++)
    {
        Console.WriteLine("Title: " + books[i].title + ", Author: " + books[i].author);
    }
}

public void FindBook(string t)
{
    for (int i = 0; i < books.Count; i++)
    {
        if (books[i].title == t)
        {
            Console.WriteLine("Found: " + books[i].title + " by " + books[i].author);
            return;
        }
    }
    Console.WriteLine("Book not found");
}

Description:
Both methods ShowBooks() and FindBook() have almost the same loop for iterating books.
This violates the principle of DRY, because the data access logic is repeated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant