Related changes

Jump to navigation Jump to search

Enter a page name to see changes on pages linked to or from that page. (To see members of a category, enter Categoría:Name of category). Changes to pages on your Watchlist are in bold.

Recent changes options Show last 50 | 100 | 250 | 500 changes in last 1 | 3 | 7 | 14 | 30 days
Hide registered users | Hide anonymous users | Hide my edits | Show bots | Hide minor edits
Show new changes starting from 05:19, 6 December 2022
   
Page name:
List of abbreviations:
N
This edit created a new page (also see list of new pages)
m
This is a minor edit
b
This edit was performed by a bot
(±123)
The page size changed by this number of bytes

29 November 2022

     20:02  Llamar desde una clase java a otra clase/en‎‎ 50 changes history -3,339 [Chudiang‎ (50×)]
     
20:02 (cur | prev) -83 Chudiang talk contribs Página creada con «A service locator adds additional complexity, it is one more <code>Service</code> class that needs to be initialized in our <code>main()</code> with something like <code>Se…»
     
20:01 (cur | prev) -84 Chudiang talk contribs Página creada con «If we don't expect class A to ever be reused, we can skip using <code>InterfaceB</code> and make it use directly B, making the code simpler and not complicating it for some…»
     
20:01 (cur | prev) -61 Chudiang talk contribs Página creada con «But as always, it is better to use your head than to follow recipes to the letter. The use of one or the other mechanism depends on each specific case and on the possible c…»
     
20:00 (cur | prev) -124 Chudiang talk contribs Página creada con «Which is better? Of course, it is a matter of taste. The usual thing is that when a class is going to be used in many places and you want it to always be the same instance,…»
     
19:58 (cur | prev) -67 Chudiang talk contribs Página creada con «== Inversion of Control or Service Locator? ==»
     
19:58 (cur | prev) -104 Chudiang talk contribs Página creada con «The version of <code>Service</code> we just saw is a '''service locator'''. Services (class B) are "registered" at some point <code>(Service.setB(new B());)</code> and can…»
     
19:57 (cur | prev) -64 Chudiang talk contribs Página creada con « We mentioned before that there were several variants of this option: service locator, factories, singleton, etc. The basic difference between all of them is basically wher…»
     
19:57 (cur | prev) -56 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> Service.setB (new Connection()); A a = new A(); a.aMethodOfA(); </syntaxhighlight >»
     
19:56 (cur | prev) -96 Chudiang talk contribs Página creada con «We have already achieved what we wanted, we can take A, Service and InterfaceB to any other project without having to take class B, which is no longer useful to us. Also, i…»
     
19:55 (cur | prev) -58 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> Service.setB (new B()); A a = new A(); a.aMethodOfA(); </syntaxhighlight >»
     
19:55 (cur | prev) -59 Chudiang talk contribs Página creada con «And in our <code>main()</code> we will have to do this»
     
19:55 (cur | prev) -54 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class Service { private static InterfaceB b; public static setB(InterfaceB b) { this.b = b; } public static Interface…»
     
19:55 (cur | prev) -70 Chudiang talk contribs Página creada con « To avoid this, we need to prevent <code>Service</code> from doing new directly, so we put a set method on it, like so»
     
19:54 (cur | prev) +1 Chudiang talk contribs
     
19:53 (cur | prev) -80 Chudiang talk contribs Página creada con « The "patch" as we have done it is that if we want to reuse A in another code, we have to take the <code>Service</code> class and to take this one, we also have to take cla…»
     
19:53 (cur | prev) -71 Chudiang talk contribs Página creada con «This mechanism is very useful when class B is something that will be used in many places in our program, such as a database access class, sockets, etc.»
     
19:52 (cur | prev) -59 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class A { public void aMethodOfA() { Service.getB().aMethodOfB(); } } </syntaxhighlight >»
     
19:52 (cur | prev) -73 Chudiang talk contribs Página creada con «Done, being <code>static</code>, we can call it from anywhere in our code by doing this»
     
19:52 (cur | prev) -55 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class Service { private static InterfaceB b = new B(); public static InterfaceB getB() { return b; } } </syntaxhighlight >»
     
19:51 (cur | prev) -57 Chudiang talk contribs Página creada con « The idea is to have a class, let's call it <code>Service</code>, that is the one that has the instance of B and a method to get it. Since we want to be able to call this c…»
     
19:51 (cur | prev) -60 Chudiang talk contribs Página creada con «When a class B is going to be used in many places and we want to avoid all the "mess" of putting getters and setters in the classes, there is another alternative that is to…»
     
19:50 (cur | prev) -63 Chudiang talk contribs Página creada con «Things can get really complicated, there can be many more classes that we need to pass back and forth, not just B. And there can be many levels of classes, like AAAA making…»
     
19:48 (cur | prev) -65 Chudiang talk contribs Página creada con «== Service Locator ==»
     
19:48 (cur | prev) -56 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> AA aa = new AA(); BB bb = new BB(); aa.setB(bb.getB()); </syntaxhighlight >»
     
19:48 (cur | prev) -49 Chudiang talk contribs Página creada con « And our <code>main() </code> would do something like this»
     
19:47 (cur | prev) -54 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class BB { private InterfaceB b = new B(); public InterfaceB getB() { return b; } } </syntaxhighlight >»
     
19:47 (cur | prev) -58 Chudiang talk contribs Página creada con «On the other hand, BB must have a <code>getB()</code> method that allows us to get B»
     
19:47 (cur | prev) -55 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class AA { private A a = new A(); public void setB (InterfaceB b) { a.setB(b); } } </syntaxhighlight >»
     
19:47 (cur | prev) -52 Chudiang talk contribs Página creada con «For the one hand, AA must have a <code>setB()</code> that passes B to A.»
     
19:46 (cur | prev) -60 Chudiang talk contribs Página creada con «The example we've done for A and B is pretty simple in the sense that there's a piece of code that does new A and B and then passes B to A. But in a more complex program, t…»
     
19:44 (cur | prev) -54 Chudiang talk contribs Página creada con «== Complicating the matter ==»
     
19:44 (cur | prev) -84 Chudiang talk contribs Página creada con « * Our class is more reusable, we can take it to other projects without having to take many more classes. * Our class can change its behavior by calling future classes that…»
     
19:44 (cur | prev) -56 Chudiang talk contribs Página creada con «In summary, the two advantages of using interfaces are:»
     
19:44 (cur | prev) -53 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> Connection c = new Connection(); A a = new A(c); a.aMethodOfA(); </syntaxhighlight >»
     
19:43 (cur | prev) -50 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class Connection implements InterfaceB { @Override public void aMethodOfB() { System.out.println("I am not B but Connection…»
     
19:42 (cur | prev) -133 Chudiang talk contribs Página creada con «The second advantage is the following: In our web game, possibly when A decides to make a move he will have to call someone to paint it, but in this case it may be to send…»
     
19:41 (cur | prev) -86 Chudiang talk contribs Página creada con «that is, A is smart enough to call b only if it has been previously passed to it. So we don't have to touch anything in A to take it to our new web game.»
     
19:40 (cur | prev) -57 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class A { private InterfaceB b = null; public void setB (InterfaceB b) { this.b = b; } public void aMethodOfA() {…»
     
19:40 (cur | prev) -132 Chudiang talk contribs Página creada con «The first advantage of using interfaces is the following: If we don't use an interface and A directly uses B, in our new project we would have to take both class A and clas…»
     
19:37 (cur | prev) -138 Chudiang talk contribs Página creada con «The advantages of using interface instead of directly passing class B are mainly two. Imagine class A is the algorithm for a wonderful game you just made and class B is the…»
     
19:34 (cur | prev) -56 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class A { private InterfaceB b; public A (InterfaceB b) { this.b = b; } public void aMethodOfA() { b.aMethodOfB…»
     
19:33 (cur | prev) -55 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class B implements InterfaceB { @Override public void aMethodOfB() { System.out.println("I am B"); } } </syntaxhighlight >»
     
19:32 (cur | prev) -56 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public interface InterfaceB { public void aMethodOfB(); } </syntaxhighlight >»
     
19:32 (cur | prev) -57 Chudiang talk contribs Página creada con «With the above procedure, passing class B to class A, interfaces are often used, although not necessary. The idea is that B implements an <code>InterfaceB</code> and that A…»
     
19:31 (cur | prev) -56 Chudiang talk contribs Página creada con «== Use of interfaces ==»
     
19:30 (cur | prev) -45 Chudiang talk contribs Página creada con «This is known as "inversion of control" or "IoC". Class A, instead of doing the new, waits for someone to do it and pass the instance to the Class A.»
     
19:27 (cur | prev) -57 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> B b = new B(); A a = new A(); a.setB(b); a.aMethodOfA(); </syntaxhighlight >»
     
19:27 (cur | prev) -57 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> B b = new B(); A a = new A(b); a.aMethodOfA(); </syntaxhighlight >»
     
19:27 (cur | prev) -53 Chudiang talk contribs Página creada con «And in the place where we do the new, we would do one of the following things»
     
19:26 (cur | prev) -58 Chudiang talk contribs Página creada con «<syntaxhighlight lang="java"> public class A { private B b; public void setB(B b) { this.b = b; } public void aMethodOfA() { b.aMethodOfB(); } }…»