jeudi 11 juillet 2019

want to write a class such that variable and methods declared in that class is used in multiple classes

I want to write the class in such a way that the value of the variable "monthlyInfoFile" is used in many other classes. I have written the classes as below, can someone please help me out to get the best possible approach of doing this. In GenerateMonthsInfo class, i'm calling other class method "monthsInfo" in which i need to get the value of montlyInfoFile variable declared in DetailShared class.

class DetailShared {
    static boolean monthlyInfoFile;

    public static void checkinMonth(String path) {
        File informationFile = new File(filePath + "\\months.txt");
        if (informationFile.exists()) {
            monthlyInfoFile = true;
            checkOtherInformation();
        } else {
            monthlyInfoFile = false;
        }

    }

public static void checkOtherInformation(String path) {

    File otherDir = new File(filePath + File.separator + "others");
    if (otherDir.exists()) {
    otherFolder = true;
    File[] files = otherDir.listFiles();
    FileFilter fileFilter = new FileFilter() {
    public boolean accept(File file) {
    return file.isDirectory();
    }
    };
    files = otherDir.listFiles(fileFilter);
    if (files.length == 0) {

    } else {
     for (int i = 0; i < files.length; i++) {
    File others = files[i];
    if (others.isDirectory()) {
    File[] otherFiles = others.listFiles();
    for (int j = 0; j < otherFiles.length; j++) {
    File file = otherFiles[j];
    if (FilenameUtils.getExtension(file.getName()).equals(".pdf")) {
    try {
    //logic to deal with the pdf
    } catch (IOException e) {
    //
    }
    } else {
    if (file.getName().startsWith(".docx"))
    //perform logic
    }
    }
    }
}
}
}
}
}

class PopulateTheBasics {
//methods
    public void calculateTheBilling() {
//want to get the value of monthlyInfoFile
    }

}

class GenerateMonthsInfo {
    void monthsInfo(String path) {
//want to get the value of monthlyInfoFile
        new DetailShared().checkinMonth(path);
        new PopulateTheBasics().calculateTheBilling();
    }
}

}

class Test {
public static void main(String args[]){
 new GenerateMonthsInfo().monthsInfo("c:/path/details");

}

Aucun commentaire:

Enregistrer un commentaire