Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-25-2004, 02:41 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
to put data methods inside class or not?

i have 2 classes:

customer
product

should i put all my customer functions inside the customer class? or should they be in a seperate database class?

for example, a customer has firstName,lastName ( and a LOT more properties )

should my searchCustomer(), addCustomer(), updateCustomer(), removeCustomer() etc.. be in the customer class? or should i have a seperate database class which manages the data.

there are a lot more classes than just customer and product, so if i make a database class ( as i already have ) it is going to get HUGE, .. but on the other hand, if i put all the customer methods in the customer class, will it be less efficient when i'm creating hundreds or thousands of new customer objects? ( in a search results for example )

maybe there should be a customerData class which just manages the data for the customer?

or would that be going overboard?
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 05-25-2004, 03:53 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
I don't think it will be less efficient to put more methods in a particular object, but it will be more annoying. Here's how I generally do it (I'm not claiming this is how all Java coders do it, it's just how it works for me).

I create an object to represent a Customer. This has all the properties of the customer, Last Name, First Name . . .

I then create a Util object, CustomerUtil, to interact with the database. Util isn't a standard notation, it's just what I came up with.

Don't create one database operation class, create a database operation package, and put all the "Util" classes in there (or, package them with the objects they're interacting with, it's up to you). You'll create a lot of files, but I think that's better than creating a huge file you need to hunt through for methods.

And generally speaking, my "Util" classes are all static methods, as they generally don't need to keep a state.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-25-2004, 04:09 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
great, thanks for the insight.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
someone please help kickerman97 Java 3 10-19-2004 03:19 PM
Java Class Basics: Static Methods bdl Java 0 02-29-2004 02:25 PM
What is OOP and Java? srt42 Java 0 04-07-2003 01:21 AM


All times are GMT -8. The time now is 09:51 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle