OOP mapping customer - server

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

OOP mapping customer - server

Post by jmut »

Let us say customer bought server(it could be anything really.)

How do you make this connection in OOP manner.

In DB you will probably have server_table with customer_id for each server record to represent to whome this server belongs.

Now taking OOP approache we will try to achive max decoupling...meaning Customer is a customer...server is a server (entities on their own)

How do you translete this in objects so you can easily answer these questions:
- get all servers for customer_id "N"
- get the customer who owns server "Server_Name"
- and other search capapbilities.


And mind that one customer has a lot of stuff associated with it.... there are servers, settings, other stuff. So just having a reference in the customer object to server_objects and vice verse could get very hard to maintain. Or is this normal coupling.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sounds like standard normalization to me.

viewtopic.php?t=54174
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

feyd wrote:Sounds like standard normalization to me.

viewtopic.php?t=54174
speaking DB
I don't see how much normalized it could get

server_table
server_id server_name customer_id


customer_table
customer_id customer_name


I speak for objects though...
If you mean that mapping when it comes to OOP is the same and follows same rulz as DB relations and normalization, this is another question.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

I'm not the world expert on OOP, but I'd do something like this - (and I'd also appreciate feedback from the guys here on this - I'm learning too :lol: )

I'd have an "Owner" class, and an "Ownable" class, and each "Owner" can own one or more Ownables, to be stored in an array within the Owner class

Probably, you could have your customer class extend the Owner class, and the Server class extend the Ownable class.

Am I on the right sort of track here?
Post Reply