classDiagram
class Publication {
-title: String
-year: int
-author: String
-statusPublication: enum
}
class Borrow {
+fromDate
+toDate
+borrowStatus
}
class Issue {
+publishDate
+unpublishDate
+manageDate
-issueStatus
}
class Member {
-idMember: String
+checkOutPublication()
+returnPublication()
+holdOnPublication()
}
class Librarian {
-idLibrarian
+addPublication()
+removePublication()
+holdPublication()
}
class Person {
-name: String
-surname: String
-address: String
-age:int
+getPublications()
}
Person --> Member
Person --> Librarian
Member --> Borrow
Borrow --> Publication
Librarian --> Issue
Issue --> Publication
Lab#SE03-1: Library/Book, Core-Model
Java SE Lab 03 part 1
📘 Linux Lab#SE03-1: Library/Book
Create a Maven/Gradle
Java SE Project.- And from Lab SE#00-3 use the relationship between
UserandBook.
- And from Lab SE#00-3 use the relationship between
Add the needed dependencies:
- Lombok
- Junit
- Java Faker
Create three
Javaclasses to define the Model. Java SE Classes:- Person: User, Worker, Staf, Freelancer, Author
- Publication: Book, BooItem, Multimedia, MultimediaItem
With
Junitdependency create unitary test to test objects and operations, and then integration tests.From here you should add new features once all the test are passed.
- Operations, you could think in a Manager Class o similar
- New fields/attributes and new classes
- New compositions and inherence: expand your model
- Use Factory design pattern to create new objects
1 Core classes and dependencies
You could then use these classes as follows:
moviemodel.java
import lombok.Data;
@Data
class Person {
private String name;
private int age;
}
class User extends Person {
private String username;
private String password;
}
class Staff extends Person {
private String department;
}
class Freelancer extends Person {
private String skills;
}
interface Publication {
void publish();
}
class Author extends Person {
private String authorName;
}
interface Publication {
void publish();
}
class Book implements Publication {
private String title;
private int pages;
private Author author;
@Override
public void publish() {
System.out.println("Publishing book: " + title);
}
}
class BookItem extends Book {
private int ISBN;
}
class Multimedia extends Publication {
private String title;
private String format;
}
class MultimediaItem extends Multimedia {
private int itemId;
}1.1 Dependency: Lombok
Use Lombok, link:
The @Data annotation is a
Lombokannotation that generates getters and setters for the fields of a class, as well as equals, hashCode, and toString methods based on the fields.The @AllArgsConstructor annotation is a
Lombokannotation that generates a constructor with all of the class’s fields as arguments.The @NoArgsConstructor annotation is a
Lombokannotation that generates a no-argument constructor for a class.
@Data All together now: A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields, and @RequiredArgsConstructor.
Adding lombok to your pom file: to include lombok as a provided dependency, add it to your
1.2 Dependency: Java Faker
Use Java Faker:
In pom.xml, add the following xml dependency between
pom.xml
In your Java code:
testfaker.java
import com.github.javafaker.Faker;
import org.junit.jupiter.api.Test;
Faker faker = new Faker();
String name = faker.name().fullName(); // Miss Samanta Schmidt
String firstName = faker.name().firstName(); // Emory
String lastName = faker.name().lastName(); // Barton
String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 4491.3 Dependency: JUnit 5
To configure support for JUnit Jupiter based tests, configure test scoped dependencies on the JUnit Jupiter API and the JUnit Jupiter TestEngine implementation similar to the following.
more on Java SE TDD
2 Solving discussion: UMLs
2.1 Core features: borrow and issue
2.2 Core features: publications and books
classDiagram
class Person {
-name: String
-dob: date
-id: String
}
class Author {
-authorName: String
}
class Publication {
<<interface>>
+publish()
}
class Book {
-title: String
-pages: int
-author: Author
}
class BookItem {
-ISBN: int
}
class Multimedia {
-title: String
-format: String
}
class MultimediaItem {
-itemId: int
}
Person --> Author
Book *-- Author
Multimedia *-- Author
Publication --> Book
Publication --> Multimedia
Book --> BookItem
Multimedia --> MultimediaItem
2.3 Core features: user and librarian (staf)
classDiagram
class Person {
-name: String
-dob: date
-id: String
}
class User {
-username: String
-password: String
}
class Worker {
-basePayment: double
}
class Staff {
-department: String
-category: String
-salary: double
}
class Librarian {
-idLibrarian
+addPublication()
+removePublication()
+holdPublication()
}
class Freelancer {
-skills: String
-variablePayment: double
}
class Author {
-authorName: String
}
Person --> User
Person --> Worker
Worker --> Staff
Staff --> Librarian
Worker --> Freelancer
Person --> Author
Book *-- Author
Multimedia *-- Author
2.4 Core features
classDiagram
class Person {
-name: String
-dob: date
-id: String
}
class User {
-username: String
-password: String
}
class Worker {
-basePayment: double
}
class Staff {
-department: String
-category: String
-salary: double
}
class Freelancer {
-skills: String
-variablePayment: double
}
class Author {
-authorName: String
}
class Librarian {
-idLibrarian
+addPublication()
+removePublication()
+holdPublication()
}
class Publication {
<<interface>>
+publish()
}
class Book {
-title: String
-pages: int
-author: Author
}
class BookItem {
-ISBN: int
}
class Multimedia {
-title: String
-format: String
}
class MultimediaItem {
-itemId: int
}
class Borrow {
+fromDate
+toDate
+borrowStatus
}
class Issue {
+publishDate
+unpublishDate
+manageDate
-issueStatus
}
User --> Borrow
Borrow --> Publication
Librarian --> Issue
Issue --> Publication
Person --> User
Person --> Worker
Worker --> Staff
Staff --> Librarian
Worker --> Freelancer
Person --> Author
Book *-- Author
Multimedia *-- Author
Publication --> Book
Publication --> Multimedia
Book --> BookItem
Multimedia --> MultimediaItem