views:

79

answers:

4

I have an interface named PropertyFilter which used to take a Propertyand decide if accepts it or not. And the world was good.

But now the interface changed, so that implementations may choose to add additional Propertys. For example a Customer property might get expanded into Name and Address properties.

I think it is obvious this is not a Filter anymore, but how would you call such a thing?

To clarify: the so called filter is pretty much a method with the signature

Property -> List<Property>

With an empty List denoting not accepting the Property, a List with exactly the input Property denoting accepting the property and a List with new Properties (possibly including the original one) denoting an expansion.

A: 

I'm not really sure what your new function does. If it still returns a boolean, then another name for a function which returns a boolean value is a "predicate".

If it takes a Customer and decomposes it (perhaps you have one function which takes a Customer and returns a Name, and another which returns an Address), then I might call them "accessors". This term is often used to describe a member function of an object, but I think it could apply here, too.

archbishop
See my updated question, predicate doesn't fit, I I don't think accessors fits ...
Jens Schauder
A: 

If Customer has a Name and and Address, the it is no longer a property, but an entity.

The Customer property could be a reference to a Customer entity, in which case the semantic convention for your interface still apply.

Jen
+1  A: 
  • PropertyChecker
  • PropertyValidator
  • PropertyDistillator
  • PropertyAccreditor ...

Do you already have a name for the method you mention ? It might help us find a proper name for the interface as well.

ian31
the method is currently called 'expand'
Jens Schauder
OK, so the interface has a mixed responsibility of validating and expanding properties. You might use a more general name like PropertyManager or PropertyHandler.Or, you might split the 2 responsibilities in 2 separate classes, PropertyValidator and PropertyExpander with one calling the other.I guess the solution depends on how client code uses the interface, and on whether client code is aware of the validation aspect or expansion aspect (or both).
ian31
A: 

I would add a method named validate to Property with the signature:

PropertyFilter -> Bool

The default implementation of validate simply passes this (the Property) to the filter and returns the result:

def validate (filter: PropertyFilter) = filter (this)

As a compound property, Customer overrides validate, implementing it in terms of its composite properties:

override def validate (filter: PropertyFilter) = name.validate (filter) && address.validate (filter)

This way, each Property can describe how to apply any given PropertyFilter to itself. I think you should avoid the List expansion approach.

David Siegel