oop

how to create a factory that dynamicly extend a class so its type changes but it inherents parent methods.

What I would like to do is have a static factory function that you give it a series of attributes and it returns an object that is of a previously undeclared class that extends a known class. Basically: <?php class foo{ public $a; function increment($b = 1){ $this->a += $b; } } function factory($name, $a){ //returns an ob...

Return a reference to an instance of an object in PHP

I have a singleton factory and would like it to return a reference to the object instance so that I can use the singleton factory to destroy the instance and not have instances elsewhere in my code to survive. Example of what I would like to be able to do: $cat = CatFactory::getInstance(); $cat->talk(); //echos 'meow' CatFactory::destr...

singular or plural on models controllers?

if i've got a thread model and controller. should that be in singular or plural for both the model and controller? i could show a thread and also list threads. dont know what i should use. $thread->get_lists(); // doesnt sound good $threads->show(); // doesnt sound good ...

call a static method inside a class?

how do i call a static method from another method inside the same class? $this->staticMethod(); or $this::staticMethod(); ...

could static members use nonstatic members and vice versa?

could i use nonstatic members inside a static method? eg. $this->nonStaticProperty $this->nonStaticMethod() and vice versa that is to say use static members inside non-static methods? ...

Overriding in C++

class base { public: int foo(); int foo(int a); int foo(char* b); int doSomething(int); } class derived : public base { public: int doSomething(int b); } int derived::doSomething( int b) { base::doSomething(b); //Make Something else } int main()...

Share UIWebView between multiple views?

What I'm trying to do is transfer the contents of a UIWebView from one view controller to another. I could just copy the URL and reload the page, but that would take quite a bit of time. Is there any way I could copy the UIWebView instance and then render it on an entirely different view? (I've tried making the UIWebView object on the se...

Using type object as returning type - bad practice ?

I have a method private object SetGrid(IGrid grid) { grid.PagerHelper.SetPage(1, 10); grid.SortHelper.SetSort(SortOperator.Ascending); grid.PagerHelper.RecordsPerPage = 10; return grid; } which returns an object of type object. Then I cast the object back to the previous type. var pr...

Learning PHP Class

I have some serious issues understanding PHP class from a book. It seems so difficult. I guess I am more of a visual learner. Can anyone recommend me a great resource to help me learn this better? ...

How to refer to Object attribute without knowing exact name?

I'm actually working with SOAP at the moment, and annoyingly the response name varies depending on the method I call. For example, one method will respond with.. $response->SendOrderResult whilst another responds with $response->GetOrdersStateResult Is there a way of referring to the value without knowing the name? ie something li...

Elegant command-parsing in an OOP-based text game

I'm playing with writing a MUD/text adventure (please don't laugh) in Ruby. Can anyone give me any pointers towards an elegant, oop-based solution to parsing input text? We're talking about nothing more complex than "put wand on table", here. But everything needs to be soft; I want to extend the command set painlessly, later. M...

Difference between value parameter and reference parameter ?

Difference between value parameter and reference parameter ? This question is asked sometime by interviewers during my interviews. Can someone tell me the exact difference that is easy to explain with example? And is reference parameter and pointer parameter are same thing ? Thanks ...

How do Factories and Patterns relate?

I was just reading a thread on SO that was discussing the merits of Singleton vs. Static Classes. Some people mentioned that pattern X appeared to be more of a 'factory' rather than a Singleton 'pattern'. What are the differences between a 'factory' and a 'design pattern'? ...

Modeling one to zero or one relationships (Z cardinality)

I'm struggling to find the best way to model 1 : 0,1 relationships ("may have one" or "has at most one"). I believe this is called Z cardinality. For example, suppose I have two classes Widget and WidgetTest. Not all Widgets are tested and the test is destructive so there can be at most one WidgetTest per Widget. Also assume that it's i...

Efficient method to check object for null member variables?

I have a data processor class which can only perform its primary function once all its member variables have been assigned a value: class { public $firstName; public $lastName; public $ssn; public $accessKey; public function __construct($data = null) { if (is_array($data)) { // Assign the value o...

Is it correct that part of business logic stays in the controller?

Hi having a simplified class like this that regulate a quiz game: class Game(): def __init__(self,username): ... self.username=username self.question_list=db.getQuestions() self.game_over=False def get_question(self): ... if self.question_list.is_not_empty(): return question def check_answer(answer) ...

Added benefit of a pointer, when to use one and why

I'm learning C++ at the moment and though I grasp the concept of pointers and references for the better part, some things are unclear. Say I have the following code (assume Rectangle is valid, the actual code is not important): #include <iostream> #include "Rectangle.h" void changestuff(Rectangle& rec); int main() { Rectangle rect...

Do write-only properties have practical applications?

I don't know why I started thinking about this, but now I can't seem to stop. In C# - and probably a lot of other languages, I remember that Delphi used to let you do this too - it's legal to write this syntax: class WeirdClass { private void Hello(string name) { Console.WriteLine("Hello, {0}!", name); } public...

Question about Java class

I am just learning Java as a hobby. How do I make a class define a field? E.g. private string[] biscuitlist Thank you for any help provided. ...

How to think "Tell, don't ask" in this simple example?

How would you adhere to the "Tell, don't ask" principle (henceforth "the principle") in the following simple scenario? In a Tetris game, I have Board, BlockGrid and Piece classes relevant to the following example: public class Board { private var fallingPiece:Piece; private var blockGrid:BlockGrid; ... public function mo...