File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Roadmap/27 - SOLID OCP/java Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments