Tag: 设计模式

任何Windows窗体应用程序最常见的设计模式是什么?

我问的是,因为我要使用c#开发一个客户端应用程序来显示库存数据并进行一些用户交互,所以请给我链接以获得之前阅读的最佳教程

C#是否包含有限状态机?

我最近读过boost::statechart库(有限状态机),我很喜欢这个概念。 C#有类似的机制吗? 或者可以使用特定的设计模式实现?

委托与OOP的C#策略设计模式

我想知道在实施战略设计模式时使用委托与OOP的优缺点是什么? 你建议使用哪一种? 或委托解决什么样的问题? 如果OOP更好,我们为什么要使用OOP? 谢谢! -tep

哪些是C#本机内置设计模式?

无论框架版本如何,C#都支持哪些设计模式? 我正在考虑可以在接口IObservable中找到的Observer模式等模式。 ObservableCollection,INotifyPropertyChanged等。 请在答案中提供模式的命名空间!

规格模式示例

在阅读了来自LosTechies.com的Chris Missal关于规范模式的一系列博客( 这里和这里 )后,我真的很想找到更完整的例子。 有谁知道我在哪里可以找到一个更加充实的例子,或者可能是一个使用这种模式的开源项目?

如果实现接口调用Dispose,它是否是一个漏洞抽象

考虑以下代码: public class MyClass() { public MyClass() { } public DoSomething() { using (var service = new CustomerCreditServiceClient()) { var creditLimit = service.GetCreditLimit( customer.Firstname, customer.Surname, customer.DateOfBirth); } } } 我们现在想重构它以松散地耦合它。 我们最终得到这个: public class MyClass() { private readonly ICustomerCreditService service; public MyClass(ICustomerCreditService service) { this.service= service; } public DoSomething() { var creditLimit = service.GetCreditLimit( customer.Firstname, customer.Surname, […]

如何实现Repository FindAll()方法?

我有以下存储库模式。 要求是“查找所有者姓名为Lijo的所有帐户”。 所以,我需要编写一个FindAll函数。 怎么写这个function? 限制是: 1)客户端“BankAccountService”不应使用“DBML_Project”中的类。 2)我们不应该使用GetAll方法来退出完整的帐户列表,然后进行过滤。 注意:我在处理多态性问题时遇到了这个问题:ORM实体是域实体还是数据实体? 码 namespace ApplicationService_Bank { public class BankAccountService { RepositoryLayer.ILijosBankRepository accountRepository = new RepositoryLayer.LijosSimpleBankRepository(); public void FreezeAllAccountsForUser(string userName) { //Should not use assembly ‘DBML_Project’. IEnumerable accountsForUserWithNameLIJO = null; //accountsForUserWithNameLIJO = accountRepository.FindAll(p => p.BankUser.Name == “Lijo”); } } } namespace RepositoryLayer { public interface ILijosBankRepository { List GetAll(); IEnumerable […]

如何使用DDD / CQRS编写function

我有一个银行帐户域名,如下所示。 可以有SavingsAccount,LoanAccount,FixedAccount等。 一个用户可以拥有多个帐户。 我需要添加一个新function – 为用户获取所有帐户。 编写函数应该在哪里以及如何编写? 如果解决方案遵循SOLID原则(开放原则,……)和DDD,那将是很好的。 任何可以使代码更好的重构都是受欢迎的。 注意:AccountManipulator将由网站客户端通过Web服务使用。 namespace BankAccountBL { public class AccountManipulator { //Whether it should beprivate or public? private IAccount acc; public AccountManipulator(int accountNumber) { acc = AccountFactory.GetAccount(accountNumber); } public void FreezeAccount() { acc.Freeze(); } } public interface IAccount { void Freeze(); } public class AccountFactory { public static IAccount […]

在C#中处理调用Dispose(IsDisposing)模式的目的?

这是来自MSDN的代码。 我不明白为什么这里的工作不只是在常规的Dispose()方法中完成。 使用Dispose(bool)方法的目的是什么? 谁会在这里打电话给Dispose(false)? public void Dispose() { Dispose(true); // Use SupressFinalize in case a subclass // of this type implements a finalizer. GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { // If you need thread safety, use a lock around these // operations, as well as in your methods that use the resource. if […]

如何在C#中创建Null对象

Martin Fowler的Refactoring讨论了创建Null对象以避免大量的问题 if (myObject == null) 试验。 这样做的正确方法是什么? 我的尝试违反了“构造函数中的虚拟成员调用”规则。 这是我的尝试: public class Animal { public virtual string Name { get; set; } public virtual string Species { get; set; } public virtual bool IsNull { get { return false; } } } public sealed class NullAnimal : Animal { public override string Name { get{ […]