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

  • SEARCH
  • Home
  • 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 8774803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:39:32+00:00 2026-06-13T18:39:32+00:00

I have a really contrived example to as how my business objects load their

  • 0

I have a really contrived example to as how my business objects load their data. However I’d like to prevent the situation demonstrated below. I know there are shortcomings here, but it’s just how it is (so far)! How can I achieve this without restructuring to interfaces etc?

Public Class Car

  Public Property Passengers As Integer

  Public Shared Sub Fill(c As Car, r As SqlDataReader)
    Passengers = r.GetInt32(0)
  End Sub

End Class

Public Class UsedCar
  Inherits Car

  Public Property PreviousOwner As String

  Public Shared Sub FillUsed(l As Limo, r As SqlDataReader)
    Passengers = r.GetInt32(0)
    PreviousOwner = r.GetString(1)
  End Sub

End Class

Public Sub CreateVehicles()

  Dim c As New Car()
  Car.FillWithStuff(c, GetSqlReader(carId))

  Dim l As New UsedCar()
  UsedCar.FillUsed(l, GetSqlReader(usedCarId)) 'Great
  Car.Fill(l, GetSqlReader(usedCarId)) 'No! << Stop this at once!
  UsedCar.Fill(l, GetSqlReader(usedCarId)) '<<< Even more wrong!

End Sub
  • 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-06-13T18:39:33+00:00Added an answer on June 13, 2026 at 6:39 pm

    There is no way to require that except to throw an exception. For instance:

    Public Shared Sub FillWithStuff(c As Car)
        If Not (TypeOf c Is Car) Then
            Throw New Exception("Must be a Car")
        End If
        Passengers = 4
    End Sub
    

    However, the simplified example you provide doesn’t adequately explain why, in your situation, a limo is not a valid car. If, in fact, it is not a valid car, then it should not inherit from car. It is likely that your code ought to be refactored so that car and limo are two unrelated classes that both share the same dependency business class for common functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a really confusing problem. I have a UIWebView that is contained within
I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag |
I have really basic question. How can I get form id by input element
I have really no idea why I'm asking this as this a really completely
Im new to iPhone development and I have really taken this to me. I
I've got a program where a lot of classes have really complicated configuration requirements.
I'm using Filemaker Pro 12 Advanced. I have a few tables but have really
Have a really large table consisting of 8 fields (I know, unprecise). In my
I really have problem with this one. So I have a jar with a
I really have no idea what I did to cause this exception, but I

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.