三层架构是很常见的架构方式,被很多公司所使用,特别是asp.net。优点是使用简单,缺点是BLL层与DAL层经常会很多重复。
SomeBLL bll=new SomeBLL( ); bll.doSomething( );
public class BLLCreator { private static SomeBLL _someBll; public static SomeBLL CreateSomeBLL( ) { if(_someBll == null) { _someBll = new SomeBLL( ); } return _someBll; } } public class SomeBLL() { private SomeDAL someDal = new SomeDAL( ); protected internal SomeBLL() { // todo something init here } public void doSomething() { } } public class Page1:WebPage { SomeBLL someBll = BLLCreator.CreateSomeBLL( ); someBll.doSomething( ); }
搞定。以后无论多少人访问,永远是一个对象。当然,如果想用泛型什么的,自由发挥了。
原文:http://www.cnblogs.com/fyan888/p/sancengbug.html