oop

Parameters vs. Attributes(class variables)?

In OOP, is it better to use class attributes within class functions, or just pass parameters to them. class User{ private $user = array(); public function Get_Existing_User($user_id){ //SQL selects user info for existing user $this->user = mysqli_fetch_assoc(); } public function Set_User($user_data){ $this->user = ...

Why is my for loop stopping after one iteration?

Racking my brains on this one. I have the code below: the first stages of a JavaScript game. All the objects are well-defined and I'm using jQuery for DOM interaction. The puzzle is created with the following JS code: var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}"); Howev...

Domain Driven Design: How to Retrieve Lists of Complex Data

I have been building a new application using my current understanding of domain driven design. So far I have a bunch of classes representing entities in my domain and a repository to retrieve from/persist to the database. The problem I am running into is that in the UI I have a need to display a few lists where the items in the list do...

PHP/MySQL isolating database access in a class - how to handle multiple row result set in an OOP manner

PHP/MySQLisolating database access in class - how to handle multiple row Selects Here’s a coding question. I isolated all DB access functions in a class <?php class DB { var $conn; function DBClass () { @$this-> conn = mysqli_connect (DB_SERVER, DB_USER, DB_PASS, DB_NAME); } function validateUse...

C++-like usage of Moose with Perl for OOP

I've been playing around with Moose, getting a feel for it. I'd like an example of pure virtual functions like in C++ but in Moose parlance (specifically in a C++-looking way). I know that even with Moose imposing a stricter model than normal Perl, there's still more than one way to do what I'm asking (via method modifiers or SUPER:: cal...

Real world oop example?? (php)

Im trying to learn OOP, but the so called 'real world' examples in the books im reading arent helping me at all. I already know that some people think that learning oop for php is unnecessary, so i don't need more people telling me the same thing. All the examples like Pet, Car, Human arent helping me anymore. I need REAL LIFE examples t...

Preferred method for initializing a child class parameters in Java?

I have an application that takes some input and generates configuration files as output. Since the exact input or output format could change over time, I defined two interfaces: Importer and Exporter. Each concrete importer or exporter could have different parameters that need to be initialized to work. For example, if the import data i...

Is it bad practice to make a setter return "this"?

Is it a good or bad idea to make setters in java return "this"? public Employee setName(String name){ this.name = name; return this; } This pattern can be useful because then you can chain setters like this: list.add(new Employee().setName("Jack Sparrow").setId(1).setFoo("bacon!")); instead of this: Employee e = new Employee...

C++ class design problem

I have a class that executes the MSNP15 protocol. The protocol requires clients to perform frequent connection/disconnection to various servers like the dispatch server, login server and the switchboard server. I decided to store the protocol related variables ( like ticket tokens, nonce etc ) as static member variables in a utility cl...

Why is the value or constructor 'handler' not defined?

I tried to use object expression to extend the IDelegateEvent, but in fsi there was an error FS0039: The value or constructor 'handler' is not defined. My codes are as follows: type IDelegateEvent<'Del when 'Del:> Delegate> with member this.Subscribe hanlder = do this.AddHandler(handler) { new IDisposable with membe...

PHP Data Access to Multiple Records

So currently I am using a pattern to grab a data entry (record). It works great for me if I only need to work with one record. However if more than one record is involved it gets more complicated. Here is my base pattern, using a contacts table: class Contacts_Entry { private $_entry = Array('contact_id' => false, ...

Override method - to call overriden implementation (super) or not to call?

Is there some rule of thumb for that decision? I always stuck with this question. Even if I know that currently I don't need the result of overriden method, how can I be sure that in the future the overriden method won't be modified? For example, there is a possibility that author of the parent class that I'm extending will decide to imp...

What do you use if you want to ensure that all methods and properties are implemented

Hi All, I was giving a test and got one question. QUESTION: What do you use if you want to ensure that all methods and properties are implemented? a)Inheritance. b)Polymorphism. c)Encapsulation d)Interface. I think its Interface. Am I right or the. ans is diff? ...

Where Can I Find Examples of Procedural Code Converted to Object Code....

I'm trying to wrap my head around Object Oriented programming. But I'm having some trouble. I (think) I understand the general concepts and the arguments for why OOP is a 'good' design. My problem comes when I sit down and try to write code that is OOP. I tend to end up with programs that are either very procedural but have the occas...

PHP/MySQL OOP: Loading complex objects from SQL

So I'm working on a project for a realtor. I have the following objects/MySQL tables in my design: Complexes Units Amenities Pictures Links Documents Events Agents These are the relationships between the above objects. Complexes have a single Agent. Complexes have multiple Units, Amenities, Pictures, Links, Documents, and Events. Un...

Good reference for Object Oriented Design

I find myself rarely using object oriented principles when I design applications. I am looking for a good reference for Object Oriented design. I'm using C# as my programming language and would like to have a reference which helps to make use of the OO contructs provided by C#. But basically I need a good book to derive some inspiration....

Correct Implementation of Virtual Functions in PHP?

Hi guys, at my working place (php only) we have a base class for database abstraction. When you want to add a new database table to the base layer, you have to create a subclass of this base class and override some methods to define individual behaviour for using this table. The normal behaviour should stay the same. Now I have seen ma...

What is the best way to differentiate between derived classes of a base class?

I have base class BaseClass and derived classes DerivedA, DerivedB, and DerivedC that all inherit BaseClass. I have another class, ExternalClass with a method that accepts a parameter of type BaseClass, but is actually passed a derived class. What is the best way to differentiate between these classes in ExternalClass if I wanted to per...

using another object's functionality following a proper OO design - encapsulation

Hello, I am debating the proper, OO-design to use another object's functionality (methods) from a java class, while both objects remain decoupled as much as possible. For example, at some point in my class, to implement my logic, I need to call a method that belongs to another object, say a helper class. This helper class does not need...

Converting Procedural PHP to OOP PHP

Hi, is there any easy way to convert Procedural PHP to OOP PHP. I've a web application, and currently, only the login system is in OOP. Thanks :) ...