Qusetion regarding Properties


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Qusetion regarding Properties

  1. #1
    max caber Guest

    Qusetion regarding Properties


    I would like to declare a property in an interface or as abstract in an abstract
    class. The concrete class would then be forced to override the property,
    just like you can do with methods.
    This is required for a "factory method" that returns a "public not creatable
    object" by using a public interface or public abstract class as the return
    type. However, as far as I know you can only define methods in an interface
    and only methods can be declared as abstract in an abstract class.

    Public Class Factory

    Public Function CreateObject() As IPublicInterface
    Return new IPublicInterfaceImpl()
    End Function

    Private Class IPublicInterfaceImpl Implements IPublicInterface

    End Class

    End Class

    I can only get the above to support methods, not properties.



    Any ideas?
    Max

  2. #2
    Mattias Sjögren Guest

    Re: Qusetion regarding Properties

    Max,

    >However, as far as I know you can only define methods in an interface
    >and only methods can be declared as abstract in an abstract class.


    No you can declare any member you want. Just remember that they
    shouldn't have a body.

    Property Prop As Integer


    Mattias

    ===
    Mattias Sjögren (VB MVP)
    mattias @ mvps.org
    http://www.msjogren.net/dotnet/

  3. #3
    max caber Guest

    Re: Qusetion regarding Properties


    Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    >Max,


    >
    >Property Prop As Integer

    Thanks Mattias,
    Do you have the syntax to do the same in C#?
    Thanks,
    Max

  4. #4
    Mattias Sjögren Guest

    Re: Qusetion regarding Properties

    Max,

    >Do you have the syntax to do the same in C#?


    public int Prop { get; set; }

    Remove the get or set keywords to make it a readonly or writeonly
    property.


    Mattias

    ===
    Mattias Sjögren (VB MVP)

  5. #5
    max caber Guest

    Re: Qusetion regarding Properties


    Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
    >Max,
    >
    >>Do you have the syntax to do the same in C#?

    >
    >public int Prop { get; set; }
    >

    Thanks Mattias,
    I knew that there had to be a way, I tried about 6 different syntax attempts,
    but I would have never come up with that, because I have never seen curly
    braces in an interface before.
    Thanks again,
    Max

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center