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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:48:20+00:00 2026-06-10T15:48:20+00:00

In recent reading, I see conflicting recommendations on encapsulation methods and OOP best practices.

  • 0

In recent reading, I see conflicting recommendations on encapsulation methods and OOP best practices.

I am beginning development of a series of PHP classes that will be used to transport and transform data from multiple source systems to a final destination. Therefore, the properties of the first class are to contain source URL and authentication values.

Which of the following is best for a long-term project with unlimited potential for expansion?

  1. Declare as public properties. Set values externally for each source when constructing class. Pro: simple. Con: No encapsulation advantage

  2. Use __get and __set. Set values externally for each source. Pro: Follows OOP convention. Con: Opens all to external access; again, no encapsulation

  3. Declare properties as protected. For each source system I need to work with, extend the original class and set the properties in the subclass. Pro:OOP with encapsulation. Con: more classes, and potentially files, to manage.

Currently, option 3 seems the best, despite the file overhead. I’m also open to other ideas.

References I have read for this question:

http://typicalprogrammer.com/?p=23

Getter and Setter?

http://www.php.net/manual/en/language.oop5.overloading.php

Independent getter/setter methods, or combined?

http://martinfowler.com/bliki/GetterEradicator.html

Is it worth making get and set methods in OOP?

  • 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-10T15:48:21+00:00Added an answer on June 10, 2026 at 3:48 pm

    There is at least one more option: inject these parameters into the objects on construction and make them read-only “properties” through a getter. Construct objects only through a factory (you can possibly enforce this as well but I ‘m not sure if there’s any tangible benefit in doing so).

    The factory can be configured on startup (which could be a plus), there is only one class of transport, and consumers can only view each transport’s state in the manner it chooses to expose it (encapsulation).

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

Sidebar

Related Questions

I was just reading a recent question on using conditionals in Linq and it
I am reading in the F# specification - the most recent one that I
I've recent been reading about immutable strings Why can't strings be mutable in Java
Recent JVM's have a lot of XX parameters for garbage collection (see here for
In reading this recent question about an unhandled XmlException, I tried to reproduce it
Reading what is currently the top answer to a recent question on how/whether to
From some recent testing and reading I've done, it seems the X (exclusive) name
I've got a series of .txt files that I'm reading in a for loop.
Reading a recent question I identified the function being discussed (def fib-seq (lazy-cat [0
I'm reading Beginning Rails 3. The book creates a project where Users can post

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.