我正在编写一个类来封装一些业务规则,每个业务规则都由布尔值表示.该类将用于处理InfoPath表单,因此规则通过使用XPath操作在全局
XML数据结构中查找值来获取当前的程序状态.什么是最好的(最惯用的)方式来暴露这些规则给呼叫者 – 属性或公共方法?
Rules rules = new Rules(); if ( rules.ProjectRequiresApproval ) { // get approval } else { // skip approval }
Rules rules = new Rules(); if ( rules.ProjectRequiresApproval() ) { // get approval } else { // skip approval }
public class Rules() { private int _amount; private int threshold = 100; public Rules() { _amount = someExpensiveXpathOperation; } // rule property public bool ProjectRequiresApproval { get { return _amount > threshold } } }
规则类暴露规则作为方法
public class Rules() { private int _amount; private int threshold = 100; public Rules() { _amount = someExpensiveXpathOperation; } // rule method public bool ProjectRequiresApproval() { return _amount > threshold; } }
一个人的利弊是什么?