Object-oriented programming ideas - Abstract

How to understand the abstract:

We went definition of a structure in front of the time, in fact, the common property of a class of things (fields) and behavior (methods) are extracted to form a physical model (template). This method is called abstract research question.

Case presentation:

type Account struct {
  AccountNo string
  Pwd string
  Balance float64
}

// method
// 1. Deposit
FUNC (the Account the Account *) deposite (Money float64, String pwd) {
  // look at the input of the password is correct
  IF pwd! = Account.Pwd {
    fmt.Println ( "The password you entered is not correct ")
    return
  }

  // to see the deposit amount is correct
  IF Money <= 0 {
    fmt.Println ( "the amount you entered is incorrect")
    return
  }

  + = Money account.Balance
  fmt.Println ( "Success Deposit")
}

// withdrawals
FUNC (the Account * the Account) the Withdraw (Money float64, String pwd) {
  // look at the password is correct
  IF pwd! = Account.Pwd {
    fmt.Println ( "The password you entered is incorrect")
    return
  }

  // to see the withdrawal amount is correct
  IF Money <= 0 || Money> account.Balance {
    fmt.Println ( "the amount you entered is incorrect")
    return
  }

  account.Balance - = Money
  fmt.Println ( "successful withdrawal")
}

// check balances
FUNC (the Account the Account *) Query (String pwd) {
  // look at the password is correct
  IF pwd! = Account.Pwd {
    fmt.Println ( "The password you entered is incorrect")
    return
  }

  fmt.Printf ( "Your account balance is =% v =% v \ the n-", account.AccountNo, account.Balance)
}

func main() {

  account := Account{
    AccountNo : "gs1111",
    Pwd : "666666",
    Balance : 100.0,
  }
  account.Query("666666")
  account.Deposite(200.0, "666666")
  account.Query("666666")
  account.WithDraw(150.0, "666666")
  account.Query("666666")
}

Guess you like

Origin www.cnblogs.com/green-frog-2019/p/11408224.html