In many Umbraco examples i see two different approaches for the same types of work. Sometimes people select, query and return INode. Other people do everything with Node.
Can anyone tell me which is the preferred way of working?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not familiar with Umbraco, but I don’t think that the answer has to be specific to it.
If you return
INode, it gives you flexibility in the future in that you can return (internally) any class that extends fromINode. ifINodecontains all properties and methods ofNode, then no functionality is lost from doing this.Take for example, the opportunity of using
IEnumerablevsListBoth the following definitions of
MyMethodwould be valid in this class example.This lets you change the implementation of
MyMethodwithout having to modify each caller.For your methods, you should return the simplest type that gives all the functionality relavant to its context. Say if you need to modify the list that
MyMethodreturns, then returningIEnumerableis a bad choice (as it’s immutable).