Retuning class or interface

Last post 07-04-2009 7:39 AM by sujithukvl@gmail.com. 3 replies.

Sort Posts:

  • Retuning class or interface

    07-03-2009, 7:19 AM

     

    I have Interface IPageObject

     I also have class PageObject implements IPageObject

     

    Here

    Function GetById(ByVal pageObjectId As String) As IPageObject

    or

    Function GetById(ByVal pageObjectId As String) As PageObject

    Which is better and why

    :(

    Filed under:
  • Re: Retuning class or interface

    07-03-2009, 8:19 AM
    Answer
    • Star
      12,312 point Star
    • Mr^B
    • Member since 02-12-2006, 11:38 AM
    • Posts 2,181

    Why would you want to pass the concrete implementation of the Interface rather than the Interface?

    Why is there an Interface there if you aren't going to use it?

    MCSD.Net
  • Re: Retuning class or interface

    07-03-2009, 8:32 AM
    Answer

    Returning Interface can be handy as it implements OOPS concepts.


    Saurabh Nijhawan(B.Tech. CSE,GGSIPU,New Delhi)
    Application Architect, Eminent Solutions, New Delhi.
    Freelancer | Teacher
    Remember to click "Mark as Answer" on the post, if it helped you.
    ASP.NET Weblog
    http://www.saurabhnijhawan.com
    Learning Made Easy


  • Retuning interface is fine.

    07-04-2009, 7:39 AM
    Answer

    One more advantage I found over returning interface is that, if a person wants a property

     

    to be exposed as public (to be available in other class) He is force to write it in the interface

     

    Not just in the class

     

    ie he also want it in interface ie our return type.

     

    so he write all properties  in the interface that are going to be public  in class.

     

    this gives good control, every thing public in class will be there in interface and this is good

     

    Filed under:
Page 1 of 1 (4 items)