IPredicateExpression Question

Posts   
 
    
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 23-Oct-2007 16:20:05   

I am sure someone on the board can tell a the answer to a most likely easy question. Why in the examples we see posted on the forums and in some of the help does this occur?

IPredicateExpression p = new PredicateExpression();

versus

PredicateExpression p = new PredicateExpression();

What is the difference between the two? Is there a certain set of circumstances to use one over the other?

Thanks, Wade

Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 23-Oct-2007 21:21:02   

Frans,

Any chance you can answer this for me? confused

Thanks, Wade

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 24-Oct-2007 00:18:36   

I've dive into the source code to find the answer, and I found that the IPredicateExpression interface is implemented only by the PredicateExpression class, so my best guess is that is just good programming practices.

I suppose it was coded that way in case we need another kind of PredicateExpresion class in the future.

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 24-Oct-2007 15:07:03   

By implementing an interface it allows someone else (e.g. you or I) to create our OWN implementation of that interface and use it instead of the vendor supplied implmentation.

Interchangably and without the vendor having to provide additional extensions.

As far the the vendors internal code goes, the vendor may only provide one implementation, but the USAGE in the rest of the vendors code utilizes interface types instead of implementation types. That is what allows us to substitue our own impementation.

So if at all possible, use this format:


IPredicateExpression p = new PredicateExpression();

That will allow you to change the implementation of IPredicateExpression in one place and all code that knows how to utilize an object that implements the IPredicateExpression interface will continue to work without modification.

So if you created your own, you would change it to:


IPredicateExpression p = new MyPredicateExpression();

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Oct-2007 16:46:15   

What is the difference between the two? Is there a certain set of circumstances to use one over the other?

If you are not going to implement your own PredicateExpression (most users find no need for that), then there is no difference between both ways of coding.