Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 332825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:54:10+00:00 2026-05-12T09:54:10+00:00

I am trying to develop a simple interface for allowing quick lists to be

  • 0

I am trying to develop a simple interface for allowing quick lists to be generated from classes. Basically, the interface needs to return an ID and a Name. However, some classes have a calculated name property which is read only, others just use a read/write name property. Basically, all I care is that it has a getter, it does not matter if the property has a setter. How can I write this interface to handle either or without throwing compile errors?

I have read this question and didn’t really follow it, maybe I am just dense. If so, please show me the error of my ways 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:54:10+00:00Added an answer on May 12, 2026 at 9:54 am

    Looks like the answer from the other question will work: here’s a sample:

    Public Interface IReadOnly
        ReadOnly Property Name() As String
    End Interface
    
    Public Interface IReadWrite
        Inherits IReadOnly
    
        Overloads Property Name() As String
    
    End Interface
    
    Public Class ReadOnlyClass
        Implements IReadOnly
    
        Private _Name
        Public ReadOnly Property Name() As String Implements IReadOnly.Name
            Get
                Return _Name
            End Get
        End Property
    End Class
    
    Public Class ReadWriteClass
        Implements IReadWrite
    
        Private ReadOnly Property ReadOnly_Name() As String Implements IReadOnly.Name
            Get
                Return Name
            End Get
        End Property
    
        Private _Name As String
        Public Overloads Property Name() As String Implements IReadWrite.Name
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
    End Class
    

    The above approach will actually result in classes that implement IReadWrite also implementing IReadOnly–so you’ll actually need to downcast to IReadWrite in order to set the property.

    Another approach, which avoids that issue but requires a little more logic in the implementing classes and their caller’s is something like:

    Public Interface ISometimesWritable
        Property Name() As String
        ReadOnly Property AllowNameEdit() As Boolean
    End Interface
    
    Public Class ReadOnlyClass
        Implements ISometimesWritable
    
        Public ReadOnly Property AllowNameEdit() As Boolean Implements ISometimesWritable.AllowNameEdit
            Get
                Return False
            End Get
        End Property
    
        Private _Name As String
        Public Property Name() As String Implements ISometimesWritable.Name
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                Throw New NotSupportedException("Name cannot be set when AllowNameEdit is False")
            End Set
        End Property
    End Class
    
    Public Class ReadWriteClass
        Implements ISometimesWritable
    
        Public ReadOnly Property AllowNameEdit() As Boolean Implements ISometimesWritable.AllowNameEdit
            Get
                Return True
            End Get
        End Property
    
        Private _Name As String
        Public Property Name() As String Implements ISometimesWritable.Name
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property
    End Class
    

    Update: To answer the question about downcasting; “downcasting” is a term used to describe casting an object from a superclass, interface, or abstract base class Type into a more concrete Type.

    For example, the first example above defines two interfaces: IReadOnly and IReadWrite. You’ll notice that IReadWrite implements IReadOnly, which means that you can make both IReadWrite and IReadOnly calls to objects which implement IReadWrite.

    Since IReadWrite implements IReadOnly, IReadWrite is said to be a “sub-class” of IReadOnly (although “sub-class” is more accurately used to describe a class which inherits a base class, rather then implements an interface–for the sake of simplicity they are very nearly the same concept). If IReadWrite is a sub-class of IReadOnly, then the inverse is true–IReadOnly is a super-class of IReadWrite.

    For example, I can describe an instance of ReadWriteClass as an implementation of either interface:

    Public Sub SomeMethod()
        dim readOnlyInstance as IReadOnly = new ReadWriteClass()
        Console.WriteLine(readOnlyInstance.Name)
    
        ' The following line won't compile, since we're communicating with ReadWriteClass as an instance of IReadOnly
        'readOnlyInstance.Name = "Santa Clause"
    
        ' Here we downcast the variable to reference it by it's other interface, IReadWrite
        dim readWriteInstance = DirectCast(readOnlyInstance, IReadWrite)
    
        ' Now we can both Get and Set the value of Name
        readWriteInstance.Name = "John Doe"
        Console.WriteLine(readWriteInstance.Name)
    
        ' Note that in the above example we created *one* instance of ReadWriteClass
        ' and have provided two variables / references to the same underlying object.
        Console.WriteLine(readOnlyInstance.Name) ' <-- note that this should return "John Doe"
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'd have to go into the source because window.jQuery is… May 12, 2026 at 3:52 pm
  • Editorial Team
    Editorial Team added an answer Can Excel use itself as an RDBMS? No, but you… May 12, 2026 at 3:52 pm
  • Editorial Team
    Editorial Team added an answer If you come from a class-based, statically typed object-oriented language… May 12, 2026 at 3:52 pm

Related Questions

I'm trying to develop a firefox extension that inserts additional HTTP header fields into
I have been pouring through documentation as part of my quarter long project to
I have a list of addresses in two separate tables that are slightly off
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.