specification-pattern

How to adapt the Specification pattern to evaluate a combination of objects?

孤人 提交于 2020-01-04 14:40:49
问题 I know that the Specification pattern describes how to use a hierarchy of classes implementing ISpecification<T> to evaluate if a candidate object of type T matches a certain specification (= satisfies a business rule). My problem : the business rule I want to implement needs to evaluate several objects (for example, a Customer and a Contract). My double question : Are there typical adaptations of the Specification patterns to achieve this ? I can only think of removing the implementation of

How to combine conditions dynamically?

泄露秘密 提交于 2019-12-29 06:32:09
问题 This question is an enhancement to the already answered question How to apply multiple filter conditions (simultaneously) on a list? In the above mentioned question we have a method that applied AND operator on all the specifications. This is achieved by using LINQ All operator on the specifications. public static List<Product> GetProductsUisngAndFilters(List<Product> productList, List<Specification<Product>> productSpecifications) { return productList.Where(p => productSpecifications.All(ps

Is the Specification Pattern obsolete when you can use Dynamic LINQ?

血红的双手。 提交于 2019-12-21 04:40:58
问题 Wikipedia states that the Specification Pattern is where business logic can be recombined by chaining the business logic together using boolean logic. With respect to selecting filtering objects from lists or collections it seems to me that Dynamic LINQ allows me to accomplish the same thing. Am I missing something? Are there other benefits to the Specification Pattern that should be considered as well? Edit: I've found some posts that discuss combining LINQ and the Specification Pattern:

Design Pattern to implement Business Rules with hundreds of if else in java

為{幸葍}努か 提交于 2019-12-20 08:49:09
问题 I have to implement certain business rules with hundreds of lines of below code if this then this else if then this . . // hundreds of lines of rules else that Do we have any design pattern which can effectively implement this or reuse the code so that it can be applied to all different rules. I heard of Specification Pattern which creates something like below public interface Specification { boolean isSatisfiedBy(Object o); Specification and(Specification specification); Specification or

Combining C# code and database code in a Specification

江枫思渺然 提交于 2019-12-19 03:36:18
问题 Sometimes you need to define some business rules and the Specification pattern is a useful tool. For example: public class CanBorrowBooksSpec : ISpecification<Customer> { public bool Satisfies(Customer customer) { return customer.HasLibraryCard && !customer.UnpaidFines.Any(); } } However, I often find that I need to 'push' these rules into SQL to improve performance or to cater for things like paged lists of records. I am then left with having to write code for the rules twice, once in CLR

Specification Pattern Example [closed]

陌路散爱 提交于 2019-12-18 10:13:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . After reading a series of blogs (here and here) by Chris Missal from LosTechies.com on the Specification Pattern I am am really interested in finding more complete examples. Does anyone know where I could find a more fleshed out example or perhaps an open source project that uses this pattern? 回答1: Also take a

Delete columns in text files with specific string

两盒软妹~` 提交于 2019-12-18 07:08:48
问题 I would like to delete collumns with a specific string "Gtype." from a .txt tab delimited file. I already have tried this command in R: df <- df[, -grep("GType.", colnames(df))] to do this task. However my matrix is too big (more than 13 GB), and R cannot deal with it. (Error: cannot allocate vector of size....) My input file: Log.NE122 Gtype.NE122 Log.NE144 Gtype.NE144 -0.33 AA 1.0 AB My expected output: Log.NE122 Log.NE144 -0.33 1.0 I am wondering that it works in bash. If someone have

How to apply multiple filter conditions (simultaneously) on a list?

巧了我就是萌 提交于 2019-12-09 06:54:56
问题 I have following C# code with .Net 4.0 framework. This is created after referring The Specification Pattern - by Jeff Perrin In the GetProducts() the conditions to be used are defined (hard coded) inside the method. There is another method named GetProductsBasedOnInputFilters() . In this method the list of specifications are made as parameter to the method. QUESTION What is the best way to apply these filters on the list of products, in this method? Note : I have tried applying the FindAll

In which layer should Specification Pattern objects be “new'ed up”?

元气小坏坏 提交于 2019-12-04 11:41:25
问题 So, I've looked at some posts about the Specification Pattern here, and haven't found an answer to this one yet. My question is, in an n-layered architecture, where exactly should me Specifications get "newed" up? I could put them in my Service Layer (aka, Application layer it's sometimes called... basically, something an .aspx code-behind would talk to), but I feel like by doing that, I'm letting business rules leak out of the Domain. If the Domain objects are accessed some other way

How to apply multiple filter conditions (simultaneously) on a list?

梦想的初衷 提交于 2019-12-03 09:49:46
I have following C# code with .Net 4.0 framework. This is created after referring The Specification Pattern - by Jeff Perrin In the GetProducts() the conditions to be used are defined (hard coded) inside the method. There is another method named GetProductsBasedOnInputFilters() . In this method the list of specifications are made as parameter to the method. QUESTION What is the best way to apply these filters on the list of products, in this method? Note : I have tried applying the FindAll clause inside a foreach loop and adding the results in a list . But that logic is incorrect - only those