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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:31:26+00:00 2026-05-28T02:31:26+00:00

is it possible to structure functions inside a class, to make some functions only

  • 0

is it possible to structure functions inside a class, to make some functions only accessable through a prewritten identifier?

I’ll try to make my question a litte more clear with a (poor) example 😉 My class car got the functions drive, openDoor, closeDoor, startEngine, etc. But, to keep it clear, i would like to acces these functions like this:

car.drive()
car.door.open()
car.door.close()
car.engine.start()

I tried with structs and nested classes, but i don’t think those were the right ways, because i don’t like to have to create an object for every “identifier” i use.

Are there any “clean” ways to do this?

Thanks!

Edit:
I’m not sure if it matters but heres some additional information:

  • the “Car”-Class is Singelton
  • apart from the functions neither the engine nor the doors or any other part of my car do have any other properties (Yay. Really poor example!)
  • 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-28T02:31:26+00:00Added an answer on May 28, 2026 at 2:31 am

    Nested classes would be the correct approach.

    Consider that all Door objects would have Open and Close methods, and a Car object would have several instances of the Door object (2, maybe 4, or even more).

    Likewise, each Car object would have an instance of the Engine object, which can be Started, Stopped, and have the oil changed (ChangeOil).

    Then, each of these classes would be extensible beyond the Car class. If you wanted to change some of the code inside of your Door class, all of your Car objects that have Doors would automatically inherit those changes. If you wanted to swap out the engine of a car with a more powerful one, you could do that easily by passing in a new instance of the Engine object to your Car object.

    You could use structs the same way that you would use classes, but generally you should choose to use a class rather than a struct. Structs should be reserved for types that should have value type semantics, i.e., are small, immutable, etc. For more information on the difference and how to make an informed decision, see this question.

    And just in case I failed to convince you that nested classes are the correct approach, I’ll conclude by noting that they’re also the only way of achieving what you want. That is, beyond hacky solutions like appending a pseudo-namespace to the beginning of each function name (i.e., Car.DoorOpen), which is ugly and doesn’t really gain you anything at all.

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

Sidebar

Related Questions

Is it possible to somehow get structure of MySQL database, or just some table
Is it possible to get the class type from inside the static initialization block?
I have a C++ application which has the following structure: Class AAA: has some
It's possible to declare variables with the below structure in C++ private: public: protected:
Is this possible in .net to see visually ,thread structure those are running (in
Is this possible in any way? My project folder structure looks like this: my_project:
I have a question about creating and managing events inside an ascx custom web
Consider the following class structure: class Filter { virtual void filter() = 0; virtual
I'm having some headaches using Structures and functions that return Nothing in VB.NET. Let
Possible Duplicate: PHP UML Generator I am trying to understand some php code that

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.