Tag: ooad

OOAD设计问题

我有两个表: tblCustomer , tblProduct : tblCustomer: Id: Integer, auto-increament Name: Varchar(30) …. tblProduct Id: Integer, auto-increament Name: Varchar(50) customerId: Integer …. 还有两个类: Customer , Product : public class Product { private int id; private int name; /* Other stuffs */ } public class Customer { private int id; private String name; private String phoneNumber; /* […]

在构造函数中尝试/捕获 – 推荐的做法?

我一直很好奇的东西 public class FileDataValidator { private String[] lineData; public FileDataValidator(String[] lineData){ this.lineData = lineData; removeLeadingAndTrailingQuotes(); try { validateName(); validateAge(); validateTown(); } catch(InvalidFormatException e) { e.printStackTrace(); } } //validation methods below all throwing InvalidFormatException 不建议在我的构造函数中包含try / catch块吗? 我知道我可以让Constructor将Exception抛回给调用者。 你们在调用像我在构造函数中所做的那样的方法时,你们更喜欢什么? 在调用类中,您更喜欢创建FileDataValidator的实例并在该实例上调用那里的方法吗? 只是有兴趣听一些反馈!