oop

persisting dynamic properties and query

Hi everybody, I have a requirement to implement contact database. This contact database is special in a way that user should be able to dynamically (on runtime) add properties he/she wants to track about the contact. Some of these properties are of type string, other numbers and dates. Some of the properties have pre-defined values, oth...

In C# or OOP, should 2 classes reference each other that are related?

I am working on a class library using C#. I have designed 3 main classes to help model our data. They are designed such that class A contains a list of class B instances, and class B contains a reference to a class C instance, ie: public class Policy { public List < PolicyTerm > myTerms; person Customer; string PolicyNumbe...

Class as an Event Observer

I want to do something like this... var Color = Class.create({ initialize: function() { this._color = "white"; this.observe("evt: colorChanged", this.colorChanged.bind(this)); }, changeColor: function(color) { this._color = color; this.fire("evt: colorChanged"); }, colorChanged: functi...

Extend window.location to store GET variables

I currently have a function that grabs the browser windows uri, parses out the variables and assigns them to a variable. This is great but I would like to extend window.location to store these. Here is the code I have but it doesn't appear to be working. Can someone explain why or how to do this? window.location.prototype.parameters = f...

What type to make child object of reference data?

I have an Object CaseNote which has numerous child object's like CaseNoteContactType. For 1 CaseNote there can be x CaseNoteContactType's. In the UI ContactTypes are shown in a CheckListBox. My question is how do I represent the ContactType child object? It is a simple int|string pair. public Class CaseNote { public Guid CaseNote...

PHP static $link from db function to db object for transactional queries

I have multiple functions, each running their own SQL query that needs to be inside a transaction... I'm using a static $link to save having to pass around links between functions... for example: function db() { $user = "username"; $pass = "password"; $db = "database"; $server = "localhost"; static $link; if(is_null($link)){ $l...

How to model Users with Roles and how to fetch them from the Database

I guess this is a common Problem: consider an application where Users have a Role You will likely have something like User username : String role : String but in your database you have CREATE TABLE IF NOT EXISTS roles ( role_id TINYINT(1) UNSIGNED AUTO_INCREMENT, role_name VARCHAR(10) NOT NULL, PRIMARY KEY...

Python - Can I access the object who call me?

If I have this: class A: def callFunction(self, obj): obj.otherFunction() class B: def callFunction(self, obj): obj.otherFunction() class C: def otherFunction(self): # here I wan't to have acces to the instance of A or B who call me. ... # in main or other object (not matter where) a = A() b = B()...

Should Interfaces be aware of Domain Objects?

In my system I have two different projects, one defining its interfaces and another defining its domain objects. So far I managed to have the interface definitions independent of the domain objects but I am feeling now the need to include certain domain objects either as parameters of the methods defined in the interfaces or as return va...

What are best practices for adding Sharepoint Fields,ContentTypes,Lists, etc.?

For our application, when the site gets installed, it creates a bunch of different fields, lists, content types, etc., etc. There are a lot of dependencies to manage there, and I'm wondering how others go about this, from an OOD perspective. ...

Difference in Django object creation call

I'd like to know if there's a difference between the following two calls to create an object in Django Animal.objects.create(name="cat", sound="meow") and Animal(name="cat", sound="meow") I see both in test cases and I want to make sure I am not missing something. thanks ...

Object Slicing, Is it advantage ?

Object slicing is some thing that object looses some of its attributes or functions when a child class is assigned to base class. Some thing like Class A{ } Class B extends A{ } Class SomeClass{ A a = new A(); B b = new B(); // Some where if might happen like this */ a = b; (Object slicing happens) } Do we say Object slicing is ...

Should class methods accept parameters or use class properties

Consider the following class public class Class1 { public int A { get; set; } public int B { get; set; } public int GetComplexResult() { return A + B; } } In order to use GetComplexResult, a consumer of this class would have to know to set A and B before calling the method. If GetComplexResult accesses man...

Class structure for an inventory control system

As an exercise in good OO methods and design, I want to know what is a good way to model inventory control in a company. The problem description is a. A company can have different types of items, like documents (both electronic and physical), computers etc which may further have their own sub types. b. The items can be kept in a...

PHP5 __get() best practice

I have a PHP class that stores a complex multidimensional array, and rather than write individual accessor methods as an interface to this array I decided to use PHP5's __get method. As I started to write these magic accessors it donned on me that I had no idea what best practices are here, so I thought I'd ask. Is one large if/else str...

How to make a natural String class in PHP

Hai. I was making this simple string class and was wondering if there was a more natural way of doing it. class Str{ function __construct($str){ $this->value = $str; $this->length = strlen($str); .. } function __toString(){ return $this->value; } .. } so now i have to use it like th...

How to release resource if the resource is passed on to a serial of objects?

I am implement a pipeline pattern, the resource is passed on to a serial of objects that will process the resource, when one object is done using the resource it passes it on to the successor, so when and which object to release the resource? ...

Class reference to parent

Hi, i'm pretty new at using C++ and I'm actually stopped at a problem. I have some class A,B,C defined as follow (PSEUDOCODE) class A { ... DoSomething(B par1); DoSomething(C par1); ... } class B { A parent; ... } class C { A parent; ... } The problem is : How to make this? If I simply do it (as I've always done in c...

functions.php vs OOP

if i have a collection of useful functions in a file called functions.php (easy enough) what would be the advantage of OOP? I want to learn it, but its pretty in depth so before I dive it, would be nice to know if there is an advantage. I can send variables to the functions just as easily as I can receive them. example i have function...

How to cross-reference objects in classes

Hi, I have a Person class and two inherited classes called Parent and Child. A Parent can have n Child(s) and a Child can have n Parent(s). What is the best way in OOD to create a reference between a Parent and a Child. Should I create a List in each class referencing the connected Parent/Child or is there a better way? BR Larre ...