oop

iPhone programming, how objects work?

Another noob question, but while looking at some code examples, I see stuff like UIViewController *controller = [[UIViewController alloc] init... Making an instance of the class UIViewController which I understand. But then you have these instance variables of your own class. Like let's say I was building a simple counter program ca...

how should I structure data for a complex object in ActionScript 3?

I hope this isn't too vague, but I'm stuck on a problem that has put me in an Unfortunate Position. I'm Flash developer getting my feet wet with with AS3 and am trying to build an interior decoration tool for a client. My thinking so far has been: create the basic user interface, get the screen flow down, and then finally use a couple o...

OOP: How would you set up an Artist, Album & Song relationship in OOP

I understand the basics of inheritance but this one is confusing me. How would you go about saying: An album object has one or more artist objects An album object has one or more song objects My current code only will only allow one song per object: class Song extends Album{} class Album extends Artist{} I'm sure i'm overlooking s...

Dependency Injection simple implementation

Hi, after reading this question i wonder if someone can help me understand how to implement correctly Dependency Injection with these PHP Classes: class DBClass { private $mMysqli; function __construct(mysqli $database) { $this->mMysqli=$database; } function __destruct() { $this->mMysqli->close(...

Data Class in ASP.Net

I am a VB.net winforms programmer attempting to build an ASP.Net app. I use data classes(objects) through reflection in most of my vb projects and was trying to adapt it to ASP.net using the VB code behind. I have a webpage that serves as an add/edit page for contact info. I instatiate my class which grabs the contact data from the data ...

Calling Parent Class Methods

Question edited to better reflect my needs. Take the following example: class Base { public $Text = null; public function __construct() { $this->Text = new Base_Text(); } } class Base_Text extends Base { public $Is = null; public function __construct() { $this->Is = new Base_Text_Is(); ...

Construct an Iterator

Let's say you want to construct an Iterator that spits out File objects. What type of data do you usually provide to the constructor of such an Iterator? an array of pre-constructed File objects, or simply raw data (multidimensional array for instance), and let the Iterator create File objects on the fly when Iterated through? Edit: ...

Which of these OOP options should I use?

I have two classes ClassA and ClassB. ClassA always needs an template file name, and ClassB extends ClassA. In usual cases when a ClassB instance is created, the user has to specify the template file name. Like: $classB = new ClassB('index'); But now I created a ClassX which extends ClassA, and when the user uses ClassX, he must not ...

When subclassing in AS3, is a new constructor function necessary?

Basic OOP question... I want to add a couple functions to the Array class so that my program will be amazing and make me rich and famous overnight. So I create a new subclass NewArray which extends Array. Do I need to write a constructor method for NewArray? If I leave it blank will it just use the parent's (Array's) constructor metho...

Design Question: Which is Better practice?

Hello, I have 3 different web servers which handle user data (username/passwd/email/etc.). I have 3 different web service calls respectively, so I've created 3 different classes which calls for the same information (getUsername, setUsername, getEmail, setEmail, etc.). From the main class I instantiate each webservice-call objects and whe...

why is OOP hard for me?

I have trouble writing OOP in PHP... I understand the concept but I never create classes for my projects... mainly because it's often a small project and nothing complex. But when I read OOP, it seems more difficult to code than writing simple procedural statements. It also seems to take a lot of room as well with so many empty abstract ...

What is the best way to represent configuration options internally?

So, I am looking at a number of ways to store my configuration data. I believe I've narrowed it down to 3 ways: Just a simple variable $config = array( "database" => array( "host" => "localhost", "user" => "root", "pass" => "", "database" => "test" ) ); echo $config['database']['host']; I thin...

Are there any patterns or is there any standard terminology for inheriting data/objects?

I have a class A that has a collection of objects of Class B. Class A can also 'inherit' (for lack of a better term) the collection of objects of Class B from other instances of Class A. To model this, instances of Class A point to other instances of Class A (I control for circular references). A simplified concrete example might be th...

What's the UML syntax for multiplicity? ( inside the class box )

I know it is possible to specify the multiplicity within the same class box, without having to draw the link to another class. My question is, Where should the multiplicity go, after the name or after the type? Is it: visibility name multiplicity : type as + clients [0..n] : Client or visibility name : type multiplicity as + ...

Most powerful and unexpected benefit of Linq in .NET OOP/D?

Since learning about Linq and gaining experience in it, I find myself leaning on it more and more. It’s changing how I think about my classes. Some of these changes were expected (ex. Using collections more) but often unexpected (ex. Getting initial data for a class as an XElement and sometimes just keeping it there, processing it lazi...

Access XAML Instantiated Object from C#

In my XAML I declare an instance of a class called DataConnection, the instance is named MyConnection. <Window.Resources> <!-- Create an instance of the DataConnection class called MyConnection --> <!-- The TimeTracker bit comes from the xmlns above --> <TimeTracker:DataConnection x:Key="MyConnection" /> ...

C++ design problem

I have a class hierarchy as such: Entity Stationary Tree Creature Bear Crow And I have a World and a Player. When the Player bumps into something it gets a call to handleCollision(Entity* entity) and then depending on what it is different things happen; if the player bumps into a tree noth...

How can a static method return a different implementation class?

I am writing a unit test by mocking out external services com.example.Service service; service = RealServiceClient.getService().getServiceId("1"); How can I simulate the above RealService class? The thing is RealServiceClient.getService() returns RealService. PS: I am new to Java. ...

Php Inheritance

Hi, I am using PHP 5.3 stable release and sometimes I encounter very inconsistent behaviours. As far as I know in inheritance all attributes and methods(private, public and protected) in super class are passed child class. class Foo { private $_name = "foo"; } class Bar extends Foo { public function getName() { retur...

How do I correctly separate the database operations from the gui/logic in c# when working with datasources?

Im having a really hard time figuring out how to specify a good search term for my problem: separation of gui and database interaction in visual studio 2008 using Linq to sql. According to my teacher in a c# class im taking it's not correct to let the GUI be dependant on a specific way of getting data. The way my project is currently s...