Skip to content

Commit 8a5b915

Browse files
committed
Ejemplo sin ocp siguiendo el ejemplo del srp de la libreria
1 parent 3dba6f8 commit 8a5b915

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import java.util.ArrayList;
3+
import java.util.List;
4+
5+
public class simonguzman {
6+
public static void main(String[] args) {
7+
libraryViolationOcp();
8+
}
9+
10+
/*************************** Ejemplo sin ocp(Incorrecto) ***************************/
11+
static void libraryViolationOcp(){
12+
Library library = new Library();
13+
library.registerBook("El quijote");
14+
library.registerUser("Juan Perez");
15+
library.loanBook("El quijote", "Juan Perez");
16+
library.returnBook("El quijote", "Juan Perez");
17+
}
18+
19+
static class Library{
20+
private List<String> books = new ArrayList<>();
21+
private List<String> users = new ArrayList<>();
22+
23+
public void registerBook(String book){
24+
books.add(book);
25+
System.out.println("Libro registrado: " + book);
26+
}
27+
28+
public void registerUser(String user){
29+
users.add(user);
30+
System.out.println("Usuario registrado: "+user);
31+
}
32+
33+
public void loanBook(String book, String user){
34+
if(books.contains(book)){
35+
System.out.println("Libro: " + book + " prestado a " + user);
36+
}else{
37+
System.out.println("El libro no esta disponible");
38+
}
39+
}
40+
41+
public void returnBook(String book, String user){
42+
System.out.println("Libro: " + book + " devuelto por " + user);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)