All Questions
Tagged with visibility oop
60
questions
0
votes
3
answers
670
views
PHP: Best practice regarding "public" visibility in OOP
Do you always add public beside methods and properties inside your classes? Or do you leave it out?
1. Option 1, without public:
<?php
class SimpleClass {
// property declaration
$var = '...
1
vote
2
answers
78
views
Restricting public accessable members - workaround
I want to break my applications model in the logical parts 'Data', 'Commands' and 'Engines'. Everyone outside the application should get a read-only access to the data and access to the commands. With ...
10
votes
4
answers
10k
views
How can I hide a class in C++?
Let's say I have 2 classes that I want to be visible (within a given header file) and one class that is their ancestor, which one I want to be visible only to the previously mentioned two. How can I ...
2
votes
4
answers
13k
views
Calling a child method from the parent class in PHP
Having the following class hierarchy:
class TheParent{
public function parse(){
$this->validate();
}
}
class TheChild extends TheParent{
private function validate(){
...
2
votes
3
answers
6k
views
How do I scope a class only to be used inside the Class Library project?
I have a class library with some public classes, and many internal utility classes. These utilities should not be visible/usable to people who link against the DLL.
namespace MyProject {
public ...
1
vote
4
answers
394
views
php oops: visibility
I'm revising my OOPs concepts in PHP. I have a simple php code here for practising visibility.
When i declare $name as private in Big_Animal,
1)Why it doesn't throw an error when i try to assign a ...
7
votes
5
answers
6k
views
PHP Visibility with Magic Methods __get & __set
I recently went to an interview and my code I supplied had magic functions to get and set variables. My code was as follows:
public function __get($name){
try {
return $this->$name;
...
14
votes
4
answers
9k
views
Why does PHP allow protected and private methods to be made public via an override in subclasses?
From some brief fiddling about, I find I get an error when overriding superclass methods in a subclass when I do the following:
Override a protected superclass method with a private subclass method
...
0
votes
3
answers
162
views
OOP Visibility, in general and specifically in PHP
This is probably a general OOP question, but I'm using PHP, so if it exists in general, I'd like to know, but give me warning if you know it's missing or warped in PHP.
Is it possible for a class ...
1
vote
2
answers
6k
views
Accessing protected variables in PHP
I'm trying to access protected variables in a second-child class extended from its parent, but every time I try to access them, they are NULL.
What's weird to me is that I can access the parent's ...
45
votes
12
answers
16k
views
Why can attributes in Java be public?
As everybody knows, Java follows the paradigms of object orientation, where data encapsulation says, that fields (attributes) of an object should be hidden for the outer world and only accessed via ...
0
votes
1
answer
50
views
With two classes extending another, how to avoid sharing an attribute
I have the following classes.
The problem is that $_instance is getting shared amongst both AuthFactory and UserFactory.
class Factory {
protected static $_instance;
/*...*/
}
class ...
44
votes
12
answers
2k
views
Why is the amount of visibility on methods and attributes important?
Why shouldn't one leave all methods and attributes accessible from anywhere (i.e. public)?
Can you give me an example of a problem I can run into if I declared an attribute as public?
2
votes
3
answers
498
views
JavaScript var visibility
Given this code:
function MyClass() {
var v = '1';
this.hi = function() {
console.log('Value of V is ' + v);
var v = '2';
console.log('Value of V is ' + v);
...
1
vote
8
answers
5k
views
Access private data member from a subclass
I would like to declare a data member of a superclass, private:
public abstract class superclass {
private int verySensitive;
abstract int setVerySensitive(int val); // must be overriden by ...