EDIT 1:ジェネリックとは、Javaのジェネリッククラスのジェネリックメソッドを意味するのではなく、プログラムの使用に不可欠であると私が書いたメソッドを意味します。
私は、サードパーティの開発者が独自の機能をタスク ネットに追加できるようにするプログラム (一種のプロセス インテグレーター) を作成しようとしています。これらのピースは、 runProcess ()メソッドを持つクラスから作成されたオブジェクトです (クラスは specialRunnable を実装します)。
objectのrunProcess ()- メソッドが呼び出されるたびに強制的にログ エントリが書き込まれるようにしたくありません。ただし、実装(ログへの書き込み)がサードパーティクラスにもメソッド呼び出しを行うクラスにもなりたくありません。
継承とインターフェイスの実装を検索して実行しようとしましたが、解決策が見つかりませんでした。これがどのように機能するかの例です。
public abstract class Process{
public void runProcess(){
// when runProcess() is called all specialized processes write to log first
writeToLog();
// then do their thing which is defined in their class
doYourProcessSpecificThing();
}
public void writeToLog(){
//writing to log comes here
}
// specialized processes have to define what is done
public abstract void doYourProcessSpecificThing();
専門クラス:
public class Special3rdPartyProcess extends Process implements specialRunnable{
runProcess(){
super.runProcess();
}
doYourProcessSpecificThing(){
// this is where the magic happens
}
私が望むことを要約すると、すべてのプロセスをrunProcess () コマンドで開始する必要があり、それが完了するたびにログエントリが必要ですが、サードパーティの開発者にエントリの書き込み方法または書き込み方法を決定させたくありません。また、次のようにしたくありません。
writeToLog();
task1.runProcess();
writeToLog();
task2.runProcess
ありがとう!