oop

Lua metatable Objects cannot be purge from memory?

Hi there, I'm using a proprietary platform that reported memory usage in realtime on screen. I decided to use a Class.lua I found on http://lua-users.org/wiki/SimpleLuaClasses However, I noticed memory issues when purging object created by this using a simple Account class. Specifically, I would start with say 146k of memory used, crea...

Extending a form field to add new validations.

I've written an app that uses forms to collect information that is then sent in an email. Many of these forms have a filefield used to attach files to the email. I'd like to validate two things, the size of the file (to ensure the emails are accepted by our mail server. I'd also like to check the file extension, to discourage attachin...

Best way to test if an object is in a set of objects?

I'm trying to avoid using a long else if statement. Lets say I have an object and I want to test if it's of type ClassA, ClassB, ClassC, etc..? What is a clean way of doing this? ...

redoing object model construction to fit with asynchronous data fetching

I have a modeled a set of objects that correspond with some real world concepts. TradeDrug, GenericDrug, TradePackage, DrugForm Underlying the simple object model I am trying to provide is a complex medical terminology that uses numeric codes to represent relationships and concepts, all accessible via a REST service - I am trying to h...

iPhone Dev: Animating PNG Sequences

What is the best or recommended technique for animating PNG Sequences. Heres what I've learned: Do it Manually Using MutableArrays containing Strings, you can animate a UIImageView with a timer which increments an index number UIImage - animation methods This works, the only problem is to find if an image has completed its animation, y...

Abstract attributes in Python

What is the shortest / most elegant way to implement the following Scala code with an abstract attribute in Python? abstract class Controller { val path: String } A subclass of Controller is enforced to define "path" by the Scala compiler. A subclass would look like this: class MyController extends Controller { override va...

Class with proprties that haven't been set

Hello there, I am creating a class in C# which eventually will be part of a library that other users can use. A user of this class has to set some properties and then use a public method to retrieve the results. What shall I do when a user calls the method without setting all the properties? Throw exception and expect the user to catch...

PHP OOP Concepts (Value Objects / Data Access Objects)

Hi, I've just started to learn PHP OOP, previously I have been doing PHP in a procedural manner. I was reading this article and I've got a couple of quick questions, How is the constructor for value objects commonly defined? As one that takes in all "data members" as parameters or stick to the default constructor and use mutator / acc...

Exposing members or make them private in Python?

Is there a general convention about exposing members in Python classes? I know that this is a case of "it depends", but maybe there is a rule of thumb. Private member: class Node: def __init__(self): self.__children = [] def add_children(self, *args): self.__children += args node = Node() node.add_children("one", "two") ...

How do I implement multiple kinds of an object in OOP?

I have multiple kinds of an object, say Car for example. Do I have each kind in an inherited class/subclass of Car? Do I place these under a cartype namespace so as not to mess up the main namespace? Then later when I need an array of cars, should I declare it as var currentCars():Car or var currentCars():Object? Would the former supp...

pass variable by reference within class? in php

I'm working on a hex color class where you can change the color values of any hex code color. In my example, I haven't finished the hex math, but it's not completely relevant to what I'm explaining here. Naively, I wanted to start to do something that I don't think can be done. I wanted to pass object properties in a method call. Is th...

Define data members within constructor

I have got this little snippet of code, I want to be able to define each array element as a new data member. class Core_User { protected $data_members = array( 'id' => '%d', 'email' => '"%s"', 'password' => '"%s"', 'title' => '"%s"', 'first_...

adding one time options to items

Hello, I'm building an Event Registration site. For any given event, we'll have a handful of items to choose from. I have a table for these items. For each event we might have special options for users. For example, for one of the events new users get to buy an item which is not available to other users. This may not apply to all t...

What patterns exist for web application development?

I understand that MVC & MVP are design patterns that are commonly used for web development, as well as ASP.NET WebForms (more of an anti-pattern, really!). What other patterns are used in web application development? I'm not necessarily saying I want to learn/use new patterns just to be different - I do believe there's a lot of value i...

Does code in the constructor add to code in subclass constructors?

Does code in the constructor add to code in subclass constructors? Or does the subclass's constructor override the superclass? Given this example superclass constructor: class Car{ function Car(speed:int){ trace("CAR speed "+speed) } } ...and this subclass constructor: class FordCar extends Car{ function For...

C# Design How to Elegantly wrap a DAL class

I have an application which uses MyGeneration's dOODads ORM to generate it's Data Access Layer. dOODad works by generating a persistance class for each table in the database. It works like so: // Load and Save Employees emps = new Employees(); if(emps.LoadByPrimaryKey(42)) { emps.LastName = "Just Got Married"; emps.Sav...

How do I write object classes effectively when dealing with table joins?

I should start by saying I'm not now, nor do I have any delusions I'll ever be a professional programmer so most of my skills have been learned from experience very much as a hobby. I learned PHP as it seemed a good simple introduction in certain areas and it allowed me to design simple web applications. When I learned about objects,...

about python scripting

I have this code class HNCS (ThreadingTCPServer): def verify_request(self, request, client_address): for key in connections: if connections[key].client_address[0] == client_address[0]: if client_address[0] != '127.0.0.1': return False return True def welcome...

Choosing a design pattern for a class that might change it's internal attributes

I have a class that holds arbitrary state and it's defined like this: class AbstractFoo { }; template <class StatePolicy> class Foo : public StatePolicy, public AbstractFoo { }; The state policy contains only protected attributes that represent the state. The state might be the same for multiple behaviors and they can be replaced at ...

ASP.Net Architecture Specific to Shared/Static functions

Hello All, Could someone please advise in the context of a ASP.Net application is a shared/static function common to all users? If for example you have a function Public shared function GetStockByID(StockID as Guid) as Stock Is that function common to all current users of your application? Or is the shared function only specific ...