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 6130527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:52:07+00:00 2026-05-23T16:52:07+00:00

I’m struggling a bit to understand the power behind OO programming. Granted I am

  • 0

I’m struggling a bit to understand the power behind OO programming. Granted I am only slightly experienced in coding in general, I was hoping this would come a lot easier than it has. For this example I created some basic code in order to determine if this is a correct/good way of containing objects within objects. If not, would you please guide me in the correct direction.

I have 2 classes: a Boy and a Dog Class. The Boy Class contains a Dog object. The Dog object knows who its owner is.

Here is a Boy class:

Public Class Boy

Protected mName As String
Public Property Name() As String
    Get
        Return mName
    End Get
    Set(ByVal value As String)
        mName = value
    End Set
End Property

Protected mAge As Integer
Public Property Age() As Integer
    Get
        Return mAge
    End Get
    Set(ByVal value As Integer)
        mAge = value
    End Set
End Property

Protected mReturnHome As New TimeSpan(3, 15, 0)
Public Property ReturnHome() As TimeSpan
    Get
        Return mReturnHome
    End Get
    Set(ByVal value As TimeSpan)
        mReturnHome = value
    End Set
End Property

Protected mPet As New Dog(Me)
Public Property Pet() As Dog
    Get
        Return mPet
    End Get
    Set(ByVal value As Dog)
        mPet = value
    End Set
End Property
End Class

And here is a Dog class:

Public Class Dog

Private _owner As Boy
Public Sub New(ByRef Owner As Boy)
    _owner = Owner
End Sub

Protected mName As String
Public Property Name() As String
    Get
        Return mName
    End Get
    Set(ByVal value As String)
        mName = value
    End Set
End Property

Protected mBreed As String
Public Property Breed() As String
    Get
        Return mBreed
    End Get
    Set(ByVal value As String)
        mBreed = value
    End Set
End Property

Protected mCanPlay As Boolean
Public Sub PlayBall()
    If Now.TimeOfDay >= _owner.ReturnHome Then
        mCanPlay = True
    Else
        mCanPlay = False
    End If
End Sub
End Class

I need to be able to gain access to the Boy Class from the Dog Class because the Dog needs to be able to recognize properties specific to its owner (Boy).

Thank you.

  • 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-23T16:52:08+00:00Added an answer on May 23, 2026 at 4:52 pm

    First off, make your variables Private, not Protected. There is no need whatsoever for derived classes to access them directly.

    Secondly, although this is done a lot in .NET, consider not having so many setters. Most properties shouldn’t change in an object’s lifetime. The exception are DTOs – objects which represent database entities.

    Also take care only to model those aspects of an object that you actually use. In real software, most attributes of a given entity are irrelevant (e.g. hair colour of the customers in a library management software) and only a few are really needed by the software. Only model those.

    Thirdly, if your Dog class needs to access specific functionality from the Boy class, the easiest recourse is to make this specific functionality Public.

    Finally, don’t pass the dog’s owner via ByRef to the constructor. This works, but makes absolutely no sense. Use ByVal everywhere except where it really is required (and I argue that it’s never required, there are better solutions).

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.