I often see people say things like "if you need friend/internal then your design is wrong", could someone tell me how to redesign the following code to eliminate the internal in ChessPiece.Location?
It's currently used so that adding a piece to ChessBoard sets the ChessPiece.Location property to match, obviously making it public would b...
Hello.
Simple question for all you pragmatic object-oriented fellas.
I have read many times to avoid classes like "Processor", and "xxxxHandler" in order to agree to OO standards: and I believe it's a good measure for understandability of the system code.
Let's assume we have a software that scans some file structure, let's say a bunch...
I'm in the process of reformatting my class ( seen below ) - I think I made the mistake of setting everything with the same visibility in my class, whereas properties should really be private and getters/setters should be public in most cases.
To grab a property I just do $path->propertyname but I've noticed its more practical to have s...
What is the purpose of these lines:
<?php $title=($cfg && is_object($cfg))?$cfg->getTitle():'Apptitle :: My First App'; ?>
<?=Format::htmlchars($title)?>
Can someone explain the usage here?
I see the top line being used as first line in a php file, then the second line being used to populate the title.
Why this implementation? Wh...
What's the best way to do something like this in PHP?:
$a = new CustomClass();
$a->customFunction = function() {
return 'Hello World';
}
echo $a->customFunction();
(The above code is not valid.)
...
Hello.
I have been trying to make OOP PHP5 code. But I think my attempts are clumsy. These are my questions:
Is their a better, more leaner way to include database config information?
Can I somehow get around having to declare $db = new Db() in every function I make?
Should I use PEAR as database abstraction layer instead of Mysqli_da...
I have a Document class that is responsible for holding the document that will eventually be gzipped and then printed onto the page. In that Document holds the document's DocType. The Problem I am facing is how to correctly implement displaying the Doctype.
For example: I could create an array of popular Doctypes that are the most frequ...
I'm just checking out anonymous methods (in c#)--part of me likes the flexibility and short-hand, but I'm also concerned that it may make the code harder to read.
It also occurred to me that this construct seems to go against some of the o/o paradigm. Do you consider anonymous methods to be in-line with object oriented principles?
...
I have following java object
Obj:
----
String id;
List<A>;
A:
--
String A_ID;
String A_PROPERTY;
What I am looking for is to be able to search in a given object. ex: search in a list where A.A_ID = 123
I need to dynamically pass
A_ID = 123
and it would give me
A_Property
I know I could search through a list through iterator, ...
Hi, I'm trying to make an object in one array equal to another. If I set each property individually, it works fine, but I want to set one object equal to antoher without writing a function to run through each property.
-(void)DrawCard: (int) wp{
[self GetNc :(wp)];
if (nc > 0){
((card*) [[Hands objectAtIndex:wp] objectAtIndex:nc]) = (...
If I put database queries in a class that is representing a real world object, does that violate the design rule that entities must not have access to data sources?
Here is an example
class User
{
public function register
{
}
private function save_user_data()
{
// database queries here, either in AR or ORM
}
}
...
I have the following code (I'm a Dot Net developers and I thought if I can bring my OOP knowledge to PHP)
class user {
var $_un;
function user($un) {
$_un = $un;
}
function adduser() {
}
function checkuser() {
}
function printuser () {
echo $_un;
}
}
$newuser = new user('Omar Abid');
$newus...
I have a strong feeling that I do not know what pattern or particular language technique use in this situation.
So, the question itself is how to manage the growing parameter list in class hierarchy in language that has OOP support? I mean if for root class in the hierarchy you have, let's say 3 or 4 parameters, then in it's derived clas...
Possible Duplicate:
Properties vs Methods
In method you can type some code and in properties too. For example I have a property Name. When class name changes I would like to get some data from database and change state of my object. I can add this code to set part of my property. Other solution is to change set part to private ...
Hi All,
I understand that the rule of thumb in OOD is to minimize access to all members of a given object as best as can be reasonably accomplished.
C# and Java both seem to implement the same set of access modifiers; however, something which has bewildered me for some time now is why Java classes seem to be mostly declared as public w...
To put it simply as an example,
public abstract class AbstractFellow {
protected Thing buddy;
....
public class ConcreteFellow extends AbstractFellow {
public void someMethod() {
buddy.doSomething();
//OR
buddy = somethingElse;
//OR
somethingElse = buddy;
}
}
Is this ba...
I know that you can call functions using variable names like this:
$foo = "bar";
function bar()
{
echo "test";
}
$foo(); // echos test
I am wondering if in a class, an actual function overrides that.
If I had this class:
class myClass{
public $test;
public function __construct()
{
$this->test = new myOtherCla...
I need some help to organize my data model well.
I am writing an app which will be a simple notebook. I use a three-tier architecture =
business-logic, data-logic, database access.
I`d like to use system of tags so it will be easier to search info in the app. Here are few questions
- due to separation of concerns, classes of entities ...
Hi all
I'm wondering if it's possible to encapsulate the methods of a class, but then expose them within a consuming class. For example (JFTR, I know this code is wrong)
class Consumer{
public function __construct($obj){
$this->obj = $obj;
}
public function doCommand(){
$this->obj->co...
Why should we use static variables or static calls to static methods in PHP5?
Maybe to improve performance?
...