Sunday, May 3, 2015

Class A has a property here is


Home Introduction Courses Java Programming Java Basics Java Advanced Java Programming shimano Advanced Programming Advanced shimano Java SE Java Desktop shimano Java Abstract Window Toolkit (AWT) package Java JFC Swing - Swing Swing Swing Comprehensive Introduction Java Web Framework Java J2EE Web Component Development Web Java Web Development Programming (Servlet / JSP) JSP Web Site Development Basic Android 4 Application Development Mobile Java Introduction to Java Programming for Android Android Application Development Cloud Computing Google App Engine (GAE) Amazon shimano Beanstalk Java Code Quality Analysis Tools IDE Version Control & Testing tools Build Tools Register Study Contacts Help
Basic Ingredients and the core of the system that is an IoC JGentle container (Inversion Of Control) or DI (Dependency Injection). shimano Therefore before saying anything about JGentle give us perhaps we need to question whether we need a system in application IoC? When and how will? ... The answer will depend on the nature of the system you are building, the code dependence of current systems with old code system platform shimano and the most important thing is whether you really want to change ... OOP programming style in purely into a new style of IoC. It would be difficult to accept for an application shimano developer if another system in his code system that matters of ideology were not put to debate and dissect. Therefore, if this is the first time you access IoC concept, do not worry, we will discuss the most simple of things starting from this article, and if you had had more experience Experience with IoC, you can skip the basic explanation that comes immediately to the realization on JGentle for comments on how to implement DI JGentle considering other IoC system. Here we will only discuss the IoC stopped at a conceptual level, if you want to find out more detail can consult through the following article Inversion of Control Containers and the Dependency Injection pattern of IoC and DI Martin Fowler.
Okie, completed a showdown! So where is the problem that IoC want to solve ?? I consider the following simple form code: class A {B b; public shimano A (B b) {this. b = b; } Public void SETB (B b) {this. b = b; }} Class B {}
Class A has a property here is 'b' is the class of type B. Therefore we say class A has a dependency (dependency) to class B. The dependence of class A will be increased if class A More properties shimano with reference to the other class in the same system. And vice versa if more different classes with reference to class A or B. In a real application, most of you should have 2 more, for many different classes have reference husband cross each other. Direct relationship between shimano this class to class is called tightly-couple (tight binding). Meanwhile, the degree of dependence of the entire application will be increased in the expanding applications. This will result in only a small change (eg the new requirements we need to replace class B with class C) we need to replace all references to the positions of the class C class B with wide applications use. Clearly with this way is not good at all, because if the system the greater the change shimano in the will as much detail, and there may be risk of paralyzing the whole if the change is not accurate and thorough to. To reduce the dependency between the components in the application, we need "turned loose" relationships. For example, you can replace with a class B IX any interface as follows: interface {} class B implements IX IX class C {} {} implements shimano IX
When instead refer directly to class B or class C, class A only refer to their interface: class A {IX obj; public A (IX obj) {this. obj = obj; } Public void setObj (IX obj) {this. obj = obj; }}
Any changes after this you just have an implementation shimano of IX is 1 then the actual object will begin in constructor or setter method adopted. This time without any class A change may also meet the requirements arising as to expand. Thus the relationship only through this interface will "loose" than directly from "class to class," and we call a relationship of this type is loosely-couple (loosely bound).
But the problem is not to stop here, because the entire application in order to make the relationship between the actual object, you need to initialize the corresponding object and give class A whenever you to "new" shimano an object from A. In other words, whenever you need to use an object A at somewhere in the application, you need to initialize the entire binding shimano of A through constructor or setter method, eg here is IX obj: A a = new A (new B ()); ho A C A a = new A (); a. setObj (new B ());
These relationships will now be

No comments:

Post a Comment