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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:35:56+00:00 2026-05-29T17:35:56+00:00

Good object-oriented design says that objects should not expose their internals. Given this is

  • 0

Good object-oriented design says that objects should not expose their internals. Given this is the case, what is the best way to display data?

For example, how would you go about displaying the data field after calling DoSomethingToData in a Console application?

public class Foo {
    string data;

    public void DoSomethingToData(string someParam) {
        .....
    }
}

class Program {
    static void Main(string[] items) {
        var foo = new Foo();
        foo.DoSomethingToData("blah");
        ..... // how do we write data field to console without breaking encapsulation?
    }
}

Update:
I thought the best way to maintain encapsulation would be to use an observer pattern (events), but no one has mentioned it. Is this a better solution than exposing a property or method result?

  • 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-29T17:35:58+00:00Added an answer on May 29, 2026 at 5:35 pm

    It depends;

    • if the value relates only to the method, make it a return value of the method
    • if the value relates to the object, expose it via a property

    I suspect it is the latter, so:

     public string Data { get { return data; } }
    

    Which is simply an accessor – the equivalent of getData() in java, for example. This isn’t exposing the field, but ultimately your object should expose some API to the information. It isn’t meant to be a complete secret.

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

Sidebar

Related Questions

Is there any website where people share and discuss good examples of object-oriented design?
I'm not good with JavaScript, and this is Google's code. I'm getting a object
I've been studying some Object Oriented Analysis and Design lately, and I feel that
I've been thinking about this object oriented design question for a while now and
i'm reading this book (Head First Object Oriented Design & Analysis). In chapter 5
My question is about how to design code that works well with object oriented
I've read that Strategy objects often make good flyweights (from Design Patterns Elements of
What is a good challenge to improve your skills in object oriented programming? The
Do extension methods follow the object-oriented paradigm in C#? Is it a good practice
Object-Oriented programmers seem to have all the fun. Not only are they treated to

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.