Sorry for ambiguous question subject, But I don't know the more proper title.
Anyway, I found a kind of style. It can be handy when you have to code rebase.
Here is a example, written by JAVA.
original code
/**
org/open/source
├── Foo.java
└── Bar.java
*/
// in Foo.java
package org.open.source;
public class Foo {
private somePrivate="kenel memory";
...
private void doSomethingWithSecret() {
system.out.println(this.somePrivate);
}
public void doIt() {
system.out.println("call Do it");
this.doSomethingWithSecret();
}
}
// in Bar.java
package org.open.source;
public class Bar {
private Foo foo;
public static void main(String args[]) {
...
foo.doIt();
}
}
// Result:
// call Do it
// kenel memory
modified code
/**
org/open/source
├── patched
| └── Foo.java
├── Foo.java
└── Bar.java
*/
// in Foo.java
package org.open.source;
public class Foo { // covert all private keyword to protected.
pretected somePrivate="kenel memory";
...
protected void doSomethingWithSecret() {
system.out.println(this.somePrivate);
}
public void doIt() {
system.out.println("call Do it");
this.doSomethingWithSecret();
}
}
// in patched/Foo.java
public Foo extends org.open.source.Foo {
@Override
protected void doSomethingWithSecret() {
system.out.println("intel meltdown it");
}
};
// in Bar.java
package org.open.source;
import org.open.source.patched.Foo; // add import statement.
public class Bar {
private Foo foo;
public static void main(String args[]) {
...
foo.doIt();
}
} // note that no code change except import statement.
// Result:
// call Do it
// intell meltdown it
PROS:
If you code like this, you can easily rebase the code when open source owner commits code. the conflicted code can be distinguished 2 types, one is "import statement", the other is "private-protected keyword".
CONS: If you in trouble after code rebase. And you don't have concrete unit test. it is very hard to find where is wrong.
I think someone finds this trick before me. this trick should have its name. What is it?
Aucun commentaire:
Enregistrer un commentaire