Object Relationship (Part 2)

Object Relationship (Part 2)

#object_oriented_deisgn #uml #class_diagrams

#Generalization (Inheritance): Represents “is a” relationship between classes

  abstract class Account{
    String accountID;
    double balance;
    public Account(String accountID)
    {
        this.accountID = accountID;
    }
    protected abstract double getBalance();
}
class SavingsAccount extends Account{
     double interestRate;
     public SavingsAccount(String accountId){
         super(accountId);
     }
     public double getBalance(){
         return balance;
     }
}        

#Realization (Interface Implementation): Concrete classes implements interfaces

public interface Exercise{
    public enum Intensity{
        LOW, MEDIUM, HIGH
    }
    public int calorieBurn(int mins);
}
public class Swimming implements Exercise{
    Intensity intensity = Intensity.MEDIUM;
    int calorieBurn;
    public int calorieBurn(int mins){
        //calculate based on intensity and minutes
        return calorieBurn;
    }
}        

# Dependency Relationship: Represents loosely coupled correction between classes.

#Usage (Dependency) Relationship: One class depends on another class to perform certain task or access certain functionality. ?



要查看或添加评论,请登录

Mohammad Iqbal的更多文章

社区洞察

其他会员也浏览了