oop

why can not use property instead of __construct?

starting use oop why: class user { private $pdo; function __construct() { $this->pdo = singleton::get_instance()->PDO_connection(); } ... } this works fine. but this: class user { private $pdo = singleton::get_instance()->PDO_connection(); ... } this does not working. Error parse error, expecting...

Can someone explain to me why this inheiritance in javascript doesnt work?

function SuperClass() { var self = this; self.someVariable = true; } function SubClass() { var self = this; self.name = "Sub"; } SubClass.prototype = SuperClass; var sub = new SubClass(); alert("This is a sub class with name " + sub.name + " and variable " + sub.someVariable); </script> </head> <body> </bod...

PHP OOP Programming Question

Im new to PHP Object Oriented Programming but I know to code in procedural way. If this is my PHP Class <?php class person { var $name; function __construct($persons_name) { $this->name = $persons_name; } function get_name() { return $this->name; } } ?> and if I access it in my PHP page $jane = new person("Jane Do...

protected field vs. protected method vs. implementing interface for action handlers

I have a class that represents a basic page with "go back", "go forward", and "canel" buttons in Wicket. But not all pages have all the buttons, e. g. the first page doesn't have "go back" obviously. My idea is to define a generic ActionHandler public interface ActionHandler { void perform(); } and let subclasses return the actions...

VB.Net cast of 2 custom types

Hi! Sorry if this question is very very basic. I need to cast, in the better way, 2 objects of 2 types of 2 custom-classes (in VB.Net): The code: Public Class pluto Public Sub New(ByVal campoPippoPass As String) _campoPippo = campoPippoPass End Sub Private _campoPippo As String = "" Public Property campoPippo...

PHP class not existing in constructor

I apologise for the unclear title, I cannot think of any better one. I'm getting this error: Fatal error: Call to a member function query() on a non-object This is caused by the constructor in a class SPConfig, which can be seen together with a class SPClasses as follows: $sp = new SPClasses(); class SPClasses { public $db, $...

Heuristics for finding class invariants.

Hello everybody! Is there any heuristics for finding class invariants, I mean pay attantion on ...; never rely on ...; Maybe there is common advices. Any links on paper where studing real-life examples will be welcome. ...

OOPs Fundamentals Concepts

Hi All, I have added this thread in order to get good hands in OOPs. I want to get depth knowledge in OOPS. Please share your knowledge and also give references for the same.. Lets starts to explore OOPs Concepts. ...

C#: DataTable conversion row-by-row

In my abstract class (C# 3) I'm using a virtual method named GetData() which returns a DataTable. The algorithm of the method is as following: Get SQL query string from the class. Get DataTable from database using above query. Do transformations on DataTable and return it. In the 3rd point, I clone the original DataTable in order to ...

Required Memory and Data Structure Layout

When a class is compiled in c# do the functions get stored with it, thus increasing the memory required? In other words is it worth creating two classes 1 to store the data and one to store all the functions with an instance of the data class? So if I have 200 instances of the data only class would it differ (memory required) from 200 ...

Class needs to handle a new type - duplicate or extend?

Suppose I have a C++ application for a pet store that started out just with Cats. The app has a class that does some data handling for a Cat dialog box: CatDlg.cpp: CatDlg::CatDlg() {//ctor stuff} CatDlg::onInitDialog() { DBAccess db; db.open(); CatRec cat; cat = db.findRec(m_catID); CString name = cat.getName(); Na...

simulate private variables in python

I've got few variables I really want to hide because they do not belong outside my class. Also all such non-documented variables render inheritance useless. How do you hide such variables you don't want to show outside your object? To clarify why I need private variables, first one example where inability to hide variables is just an i...

Where does my code go? Controller, Service or Model?

So we have a PHP+Zend Framework+Doctrine 1.2 application that has the following structure: Controller -> Action -> Service -> Model Not all models are interacted with through a service. Our current opinion is that a controller could use a model directly and a service could possibly use other services. My question is: If you have a pi...

Can an inherited @property not satisfy a <protocol> @property?

I've got a protocol: @protocol Gadget <NSObject> @property (readonly) UIView *view; - (void) attachViewToParent:(UIView *)parentView; @end And an "abstract" base class, with an implementation (as a getter, not shown) of -(UIView *)view: // Base functionality @interface AbstractGadget : NSObject { UIView *view; } @property (re...

PDO's FETCH_INTO $this class does not working

I want to populate class with constructor using FETCH_INTO of PDO: class user { private $db; private $name; function __construct($id) { $this->db = ...; $q = $this->db->prepare("SELECT name FROM users WHERE id = ?"); $q->setFetchMode(PDO::FETCH_INTO, $this); $q->execute(array($id)); ...

Class methods implementation: should it change a class' member variable or take in arguments?

I guess I'll try to explain my question through 2 code snippets: // snippet 1 class FooBar { private int value; public int DetermineSomeResult() { PerformSomeCalculationOnValue(); PerformSomeMoreStuffOnValue(); return value; } public int GetCachedValue() { return value; } } The fir...

How to store objects data into database from OOP application efficiently and easily?

Hello I design an objected oriented application using C# with database back end, for some time I was building same application using procedural way in which I feel storing data to database is little bit easier using simple SQL statement. I my application I want to store the objects attribute to database, for example for an item object ...

OOP PHP Weird undefined method

Can someone tell me why I am getting undefined method print_hash() error? I have the following class class EmailManager{ private $replytoArray; private $receiverArray; private $fromArray; function __construct(){ $replytoArray = array(); $receiverArray = array(); $fromArray = array(); } function addReceiver($k){ if(!i...

C++ class declared as static class member

Is there any problem with declaring a class with a static member which is another class in a header. E.g: class Stat { public: int avar; Stat(); }; class Test { public: static Stat stat; }; The reason I fear it might cause problems is that it seems very similar to declaring a global variable in a header. If included in tw...

How to build multi oop functions in PHP5

I have a question about OOP in PHP5. I have seen more and more code written like this: $object->function()->first(array('str','str','str'))->second(array(1,2,3,4,5)); But I don't know how to create this method. I hope somebody can help me here, :0) thanks a lot. ...