oop

random rowcount in PDO

how would i get a random rowcount using PDO? i'm still learning how to use PDO so this is what i tried, but it didn't work because it doesn't randomize the quotes: $sql = "SELECT COUNT(*) AS rows FROM thquotes;"; try { $query = $this->_db->prepare($sql); $query->execute(); ...

SQL Connection Methods and best practices

So normally I just put my sql connection string in my asp.net web.config and reference it whenever I need to open a database connection, however this leaves me with referencing it all over my project. This also exposes my sql connection username and password in my web.config if it isn't encoded. What are you best practices as far as kee...

Opensource Object Oriented Database for WPF application

Hi, I am planning to implement an application using WPF, I want to use an Object Oriented database. Could you suggest an Open Source Object Oriented Database? Thanks ...

When to implement an interface and when to extend a superclass?

I've been reading a lot about interfaces and class inheritance in Java, and I know how to do both and I think I have a good feel for both. But it seems that nobody ever really compares the two side by side and explains when and why you would want to use one or the other. I have not found a lot of times when implementing an interface woul...

Basic Object Oriented inheritance question

Consider the following source code. I have two classes CBar and CFoo. CFoo inherits from CBar. The output of this source code is Bar Foo Bar I was expecting Bar Foo Foo Where did I go wrong? What I was thinking was that since the CFoo object has a Speak function that overrides the CBar speak function. When I call The Speak()...

Should I be using inheritance?

This is more of a subjective question, so I'm going to preemptively mark it as community wiki. Basically, I've found that in most of my code, there are many classes, many of which use each other, but few of which are directly related to each other. I look back at my college days, and think of the traditional class Cat : Animal type exam...

function called in function throwing undefined function error

using the object-oriented approach, i'm trying to call a public function in a function in the same class, but it throws an error: Call to undefined function h() php: class Name { . .. . public function h($s) { echo htmlspecialchars($s, ENT_QUOTES); } public function formatQuotes($row) { return "<p id...

How do I merge two objects?

I have an object, $foo, which has some methods and properties already defined and another object, $bar, which is just a set of properties. I want to merge the entirety of $bar into $foo such that all the properties of $bar become properties of $foo. So if beforehand I had, $bar->foobar, afterwards I should be able to use $foo->foobar. ...

A (somewhat obscure) Javascript inheritance question

I have been experimenting with a design pattern in Javascript that would allow me to have what appears to be singleton functions that can be overridden by instance functions. Here's a brief example: Date.tomorrow = function () { return Date.today().add(1).days(); } (function(p) { p.tomorrow = function() { var date = this.clon...

Pass values from array to object? - PHP

My problem, simplified is: class A { public $a; public $b; function f1 () { // Code } } $obj = new A(); $arr = array ("a" => 1, "b" => 2); How can I put the contents of $arr into $obj? (Obviously without $obj->a = $arr["a"], suppose there are thousands of values) Thank you. ...

How do include and call sample code methods in Objective-C?

iPhone/Mac "play a sound class": link text I find an awful lot of great objective-c classes and code samples here... and elsewhere. I successfully create the .h and .m files, but how do I call them from my existing code? Where do I put the @class or #import statements? How do I call the methods? What if I need to play 2-3 different...

Improving a constructor

Alright, I'm working on making a Member class for my website. I want to make it as optimized as possible. Currently, the constructor can take ($resource) either an int (to grab info from one member in the database, based on id) or an array of ints (to grab multiple members from the database, and store them in an array member variable)....

Which is the best book to learn and implement Design Patterns using C#?

Which is the best book to learn and implement Design patterns available in the industry with examples? like Creational Patterns,Structural Patterns, Behavioral Patterns ? ...

What is the best way to solve this problem in a model?

I come across this a lot, and have always been curious if there is better way. Consider this (example only, assume an OO query builder) class Dogs extends Pets { public function getAll() { return $this->parseRows($this->db->get('dogs')); } public function getBig() { return $this->parseRows($this->db->get('...

GRASP's Controllers and MVC's Controllers question

Introduction to the problem I have been taught about OO Analysis and Design through Craig Larman's Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, that follows the UP(Unified Process). When using it, we usually draw a Domain Model and from it, doing Interaction/Association Di...

Destructor or Deconstructor?

In my daily life and while reading books I've seen the term destructor as well as deconstructor. But what is the correct name for this method? ...

Mimic classes in ANSI C

Hi To make a struct's members "private" to the outside I know that I can do this. In the .h file typedef struct Obj Obj; In the .c file you then struct Obj { int a; int b; } This will keep the knowledge of the existense of a and b from beeing known. But all the "member" functions in the .c file will now about them and can oppera...

PHP OOP 4/5 Compatibility?

I've read that major changes were made in PHP 5 to the OO structure, so I'm concerned (before taking up OOP PHP) that users would need a specific version of PHP installed to run my application (either 4 or 5). Up until now this hasn't really been an issue as it's just been differences like missing functions or different return values. S...

accessing the parent of an object

I'm trying to call methods on the parent of my object by passing the parent in as property. But i keep getting this error: expected specifier-qualifier-list before 'Wheel' @interface Car : NSObject { Wheel *w; } - (void)doCarStuff; @end @implementation Car - (id)init { if((self = [super init])) { //w = [[Wheel al...

Passing Class Variables to Class Method in Prototype via addEventListener

I have the following class file that I'm attempting to build. I'd like to pass multiple variables to the method by way of an eventListener but the code I have below doesn't work, probably due to scoping. NOt sure what I should change though. Any advice would be much appreciated. var MyClass= new Class.create(); MyClass.prototype = { ...