oop

What are the naming conventions and other standards used while developing a class in php?

I am pretty new to PHP classes and I want to follow the standard pattern? ...

How a member func can know *programmatically* the 'name of the object' that is calling it?

Let say we have a class MyClass that has and a memberfunc(). An object is created for this MyClass, say ObjA. i.e MyClass ObjA; ObjA calls memberfunc(). Can we get this name 'ObjA' inside memberfunc() programatically? Note: I know how to get the type of the object, i.e 'MyClass', using RTTI (Run-Time Type Identification), the sam...

how to Clean up(destructor) a dynamic Array of pointers??

Is that Destructor is enough or do I have to iterate to delete the new nodes?? #include "stdafx.h" #include<iostream> using namespace std; struct node{ int row; int col; int value; node* next_in_row; node* next_in_col; }; class MultiLinkedListSparseArray { private: char *logfile; no...

Given a PHP class would be the best and simplest way to override one or two of its methods with one of your own?

Here's the objective. I have a PHP class and there are one or two of its methods that I would like to override with my own. As I understand OOP (in PHP and in general) I could write a child class that extends it and overrides the functionality of the methods in question. However, I was wondering if this is the best way of achieving this...

What is the difference between an Instance and an Object?

What is the difference between an Instance and an Object? Is there a difference or not? ...

Building a simple cart using object orientated PHP

I've built basic shopping carts with PHP before but in an attempt to get my feet wet with OOP, I'd like to try using that method. I come from a design background but do understand some basics of OOP but would like to see a tutorial or something simple I could base this on. The site is small and the cart functionality required is very s...

Generics with constraints hierarchy

I am currently facing a very disturbing problem: interface IStateSpace<Position, Value> where Position : IPosition // <-- Problem starts here where Value : IValue // <-- and here as I don't { // know how to get away this // circular...

Object-oriented GUI development in python

Hey guys, new programmer here. I have an assignment for class and I'm stuck... What I need to do is a create a GUI that gives someone a basic arithmetic problem in one box, asks the person to answer it, evaluates it, and tells you if you're right or wrong... Basically, what I have is this: class Lesson(Frame): def __init__ (self, ...

What could possibly cause this error when declaring an object inside a class?

I'm battling with this assignment :) I've got two classes: Ocean and Grid. When I declare an object of the Grid inside the Ocean: unsigned int sharkCount; Grid grid; The compiler/complainer says: error C2146: syntax error : missing ';' before identifier 'grid' Can you possibly predict what produces this error with the limited i...

results show well in the class file, but show strange characters when I include it in the main system?

I am currently building a blog system, and the class file i.e class Blog{}, is running ok, when I try it on its own, but, when I try to use it in the pages of the site that have css, it looks weird and full stop, and apostrophes are replaced by strange characters! please help, this is my first time of using oo for development, ...

PHP: How do I access child properties from a method in a base object?

I'd like for all of my objects to be able to return a JSON string of themselves. So I created a base class for all of my objects to extend, with an AsJSON() method: class BaseObject { public function AsJSON() { $JSON=array(); foreach ($this as $key => $value) { if(is_null($value)) continu...

Could a derived-class object treated as if it's the same type of a bases class? <noobieQ/>

Say I got: class X_ { public: void do() { } } class Y_ : public X_ { } And I have this function: void foo(X_ whatever) { whatever.do(); } Can I send a "Y_" object to the foo function, would this work? I just realized that I could have tested this myself :) ...

Mutate an object into an instance of one its subclasses

Hi, Is it possible to mutate an object into an instance of a derived class of the initial's object class? Something like: class Base(): def __init__(self): self.a = 1 def mutate(self): self = Derived() class Derived(Base): def __init__(self): self.b = 2 But that doesn't work. >>> obj = Base() >>>...

What's wrong with my destructor?

// Sparse Array Assignment.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> using namespace std; struct node{ int row; int col; int value; node* next_in_row; node* next_in_col; }; class MultiLinkedListSparseArray { private: char *logf...

Exceptions confusion

Hi there. I'm trying to build site using OOP in PHP. Everyone is talking about Singleton, hermetization, MVC, and using exceptions. So I've tried to do it like this: Class building whole site: class Core { public $is_core; public $theme; private $db; public $language; private $info; static private $instance; ...

F#: Define an abstract class that inherits an infterface, but does not implement it

incorporating leppies feedback it compiles - but IMO some drawbacks I want each sub class to be forced by the compiler to define their own Uri property. Code as it is now: [<AbstractClass>] type UriUserControl() = inherit UserControl() interface IUriProvider with member this.Uri with get() = null Interesting enough,...

Is it possible to establish default values for inherited fields in subclasses?

I'm trying to establish a default value for inherited fields from superclasses. So, my class hierarchy is thus: Character -> Enemy -> Boss                 \                   -> Hero Each Character has a public static char avatar to represent him on an ASCII playing field. How do I set a default value for the avatar of each class inh...

PDO using singleton stored as class properity

Hi again. OOP drives me crazy. I can't move PDO to work. Here's my DB class: class DB extends PDO { public function &instance($dsn, $username = null, $password = null, $driver_options = array()) { static $instance = null; if($instance === null) { try { $instance =...

"string" != "string"

Hi. I'm doing some kind of own templates system. I want to change <title>{site('title')}</title> Into function "site" execution with parameter "title". Here's private function replaceFunc($subject) { foreach($this->func as $t) { $args = explode(", ", preg_replace('/\{'.$t.'\(\'([a-zA-Z,]+)\'\)\}/', '$1', $subject)); ...

Shortening code

Nah, looks like it was hosting fault. Who can make this code shorter? private function replaceFunc($subject) { foreach($this->func as $t) { preg_match_all('/\{'.$t.'\([a-zA-Z,\']+\)\}/i', $subject, $res); for($j = 0; $j < sizeof($res[0]); $j++) { preg_match('/\([a-...