I am confused between the properties of other objects (and implementing methods on the attribute) Using texture, vs
Is there a tradeoff here?
Perhaps giving easy examples of bad coupling (if there is any difference) to clarify the difference?
Edit the example:
Public class MyClass () {MyOtherClass moc; Public MyClass (MyOtherClass temp) {moc = temp; } Public Null Method () {moc.call ()}} This bad coupling is due to dependence on the structure relationship ?? If not, what would be the bad coupling in this example.
There are two basic methods related to classes legacy and composition < / Code>. When you establish a legacy connection between the two classes, you can take advantage of the dynamic binding and polymorphism . Given that succession makes relationships difficult to change the interface of a superclass, it is composition . It turns out that when your target code is reused, composition provides an approach that generates easy-to-change codes. class fruit {// return number is the piece of peel that / peel the resulting public from the public (peel) {System.out.println ("peeling is attractive."); Return 1; }} Class increases apple fruit {} Example1 {public static zero main (string [] args) {apple apple = new Apple (); Int Pieces = apple.peel (); }} If at any point in the future, you want to change the return value of peel to peel ( peel , then you break the code For Example 1 code, Example 1 example uses Apple directly and never explicitly mentions the fruits. Creation For the implementation of fruit for Apple An alternative method provides peel () . Instead of expanding the fruit, the apple is a fruit For example, a reference can be made and defines its own peel () method, which invokes the peel () . The code was given here Is: class fruit {// return number of pieces of peel, which was done with peeling activity. Public Intel Peel () {System.out.println ("Peeling attractive Returns;); Return 1;}} Class Apple {Fruit of Personal Fruit = New Fruit}, Peel Public Ink () {Return Fruit. PL ();}} Category Example 2 {Public Still zero main (string [] args) {Apple apple = new Apple (); Int pieces = apple.peel (); }} legacy gives you more coupling than composition .
Comments
Post a Comment