Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-31-2011, 01:44 PM   PM User | #1
0x001A4
New Coder

 
Join Date: Feb 2006
Posts: 33
Thanks: 6
Thanked 0 Times in 0 Posts
0x001A4 is an unknown quantity at this point
Proper OO Design

I understand the concepts of OO programming and the benefits but I often have trouble conceptualizing proper design. Most often I have difficulty when writing classes for integrations, like Quickbooks for example.

I need to write a class for an accounting software integration that uses web services to transfer data.

I'd be making calls like CreateCustomer, UpdateCustomer, CreateInvoice, GetStock, etc.

The way I'm looking at it now, I would create a class with a constructor that took no parameters. Then I'd simply call each method as I needed it and pass the necessary data to each method.

So CreateCustomer would take an array with necessary fields, and then pass that off to internal methods which would generate the xml and send it and handle the response.

My problem and the reason I think I'm doing something wrong is because when I start coding this I feel like I'm writing a library of methods. It doesnt seem like I'm writing a class.

I'm just looking for clarification on it. Is this proper OO design?
0x001A4 is offline   Reply With Quote
Old 03-31-2011, 05:56 PM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
You were right to feel weird, that isn't proper OOP design. You wouldn't have all those functions be in the same class, classes are objects so you would have a customer class, an invoice class, a stock class.

So the customer class would have all the data of a single customer. The invoice class would have all the data and functions for an invoice.

So then you would create a new instance of the invoice class, and give it an instance of the customer class and then add stock items to it. Then inside the invoice class is where you can do anything you need like totaling the price, calculating tax, etc.

Does that make sense? Some times it can be really helpful to draw the classes out so you can visualize them.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Users who have thanked oracleguy for this post:
0x001A4 (04-01-2011)
Old 04-01-2011, 01:34 AM   PM User | #3
0x001A4
New Coder

 
Join Date: Feb 2006
Posts: 33
Thanks: 6
Thanked 0 Times in 0 Posts
0x001A4 is an unknown quantity at this point
That makes perfect sense. In fact this answers a lot of my questions regarding proper design. I was taught the concepts by thinking of things like people, cars, animals. Trying to wrap my head around business objects was getting the better of me. I was thinking I'd be instantiating a "Quickbooks" object but I guess I was looking too much at the big picture and not enough at the actual components that go into accounting software.

That helps a lot, thank you.
0x001A4 is offline   Reply With Quote
Old 04-01-2011, 01:49 AM   PM User | #4
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
Quote:
Originally Posted by oracleguy View Post
Some times it can be really helpful to draw the classes out so you can visualize them.
yep, totally agree - uml diagram
bullant is offline   Reply With Quote
Old 04-01-2011, 09:58 PM   PM User | #5
0x001A4
New Coder

 
Join Date: Feb 2006
Posts: 33
Thanks: 6
Thanked 0 Times in 0 Posts
0x001A4 is an unknown quantity at this point
I started drawing it out on paper and have very decent class definitions going. I also have a parent class I'll use for shared methods and properties among classes.

So last night I downloaded the Modeling plugin for Eclipse and started putting them into a UML diagram. Its coming along nicely.
0x001A4 is offline   Reply With Quote
Old 04-01-2011, 10:14 PM   PM User | #6
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
Quote:
Originally Posted by 0x001A4 View Post
I started drawing it out on paper and have very decent class definitions going. I also have a parent class I'll use for shared methods and properties among classes.
That doesn't sound quite right. Depending on the properties and functions there might be a different/better/proper way to do it. How about you draw up your UML diagram and post it and get some feedback?
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:38 PM.


Advertisement
Log in to turn off these ads.