From the course: Java Design Patterns: Structural
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: The Composite pattern - Java Tutorial
From the course: Java Design Patterns: Structural
Challenge: The Composite pattern
(upbeat music) - [Narrator] Let's have a look at the challenge exercise for the Composite Pattern. In this challenge, you need to refactor an app for checking out library books. This has a similar structure to the expenses payments app I demonstrated in the previous videos. The app has classes for fiction books and nonfiction books. These two classes are very similar. They both have a constructor that takes a string codename, and the fiction book class also has a Boolean code as a play, as fictional books in this library can either be plays or normal books. Both classes also have a field called checked out, which is set to false in the constructor of the class. Both classes also have a method called checkouts and return book, for checking books out of the library and returning them. There's also a class called book collection, which has two fields, a list of fiction books and a list of nonfiction books. This class also…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.