jeudi 19 avril 2018

I am confused on how to implement singleton pattern to my code and get it to call on my object classes and methods

As the title suggest, I'm trying to implement the singleton design pattern to my code. My code has a main class and 3 inherited classes. I would like to create only one object that is able to use all of the functions in the code. This is my first time dealing with design patterns so my code might be everywhere. Here is the code:

class geniusATM {

    private String name, address;
    private int pin, ficoScore;
    double checkingBalance, savingBalance, mortgageBalance;

    public geniusATM() {

    }

    geniusATM(String nam, String addr, int pn, int fs, double cB, double sB, double mB) {
        name = nam;
        address = addr;
        ficoScore = fs;
        checkingBalance = cB;
        savingBalance = sB;
        mortgageBalance = mB;
    }

         //setters and getters are here
        }

       class Checkings extends geniusATM {
        //stuff here
          }

       class Savings extends geniusATM {
        //stuff here
         }

       class billPay extends Checkings {
       //stuff here

       }

     public class singletonObject {

      private static singletonObject ob;

    private  singletonObject() {
        geniusATM matt = new geniusATM("Matt", "124 Road Drive.", 1234, 3462, 560.00, 500.50, 472.29);

    }

    public static singletonObject getObject() {
        if (ob == null) {
            ob = new singletonObject();
        }
        return ob;
    }

    public static void main(String[] args) {


    }


}

Aucun commentaire:

Enregistrer un commentaire