Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 08-08-2004, 08:07 PM   #1 (permalink)
Insane
 
trache's Avatar
 
OOP Design Advice

I'm trying to program a simple daemon that (will eventually) compile in Windows and UNIX. Users will be able to login and have accounts set up, almost like a MUD, but it's not going to be a MUD.

I would like to really try my hand at programming something that's worthwhile of my time and effort, and so I would like to do it <i>right</i> (that's objective obviously)

I thought of having a few objects, namely one for the server listening, the configuration file (loading, saving), database routines (connecting, fetching, modifying information) as well as an object for the users, menus, etc etc.

I need some advice as to a good way of designing this system so that I can use an SQL database as a back end to store information. The trouble is, I know how much a database can bring a computer to its knees. Therefore, I would like to minimize the number of connections and queries to the database.

How do I go about designing each of my objects when a few of them depend on file I/O (be it database or flat-file) to load and save information persistently?

Should I have a database object (with each DB object <hopefully> only have one connection to the database) and have my user/menu objects inherit from it, or should I pass the DB object into each user and menu object ?

Hopefully it wasn't too confusing, but perhaps someone can point me in the right direction or give some sound advice in this matter.

Thanks.
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip
trache is offline  
Old 08-10-2004, 09:06 AM   #2 (permalink)
Follower of Ner'Zhul
 
RelaX's Avatar
 
Location: Netherlands
First off, kudos for wanting to do the right thing, instead of just another hack-job.

Second, on the database issue, I would go for a singleton design pattern (if you don't know anything about design patterns, look it up on wikipedia.org or something, it's amazing stuff), just make sure that you have one instance of a database object that does all the queries and has a persistent connection.

Third, if you really want to do something right, you begin with design. I would suggest you check out UML and make a couple of use-cases and a class diagram. Personally I always make ERDs and flow-charts as well, because they are more ways of thinking through the problem/situation and class diagrams can quickly become more about the solution.

Fourth, document. I dunno if you've ever seen the movie Memmento (I love that movie, in case you haven't seen it though, it's about a guy with no long term memory), but the guy from that movie should even be able to work with your code. Keep every function nice and short and well documented (in something like phpDoc or JavaDoc maybe?). This will SIGNIFICANTLY help prevent code reuse and save time in the long run.

This is my $0.02 anyway.
__________________
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
- Nathaniel Borenstein
RelaX is offline  
Old 08-16-2004, 07:37 PM   #3 (permalink)
Insane
 
Databases don't kill a system as much as you might think. Indexing (the software can do this) and good design (you should do this) should help minimize the utilization. Then again, if you're expecting to run many simulataneous users, you might want to consider other options. You might want to consider different storage options for different types of data. For structured data that's not accessed too much, you can throw that in any type of database.

I've read that Berkeley DB is one of the fastest DBs out there, but it's also more limited. Perhaps you can arrange your most common data to fit in a Berkeley DB somehow.

Sorry I couldn't be more helpful. Hopefully you can do some research on Berkeley DBs to see if you can use them.

Regarding your object design, don't worry about how everything connects to the DB. Instead, build some kind of data access object that talks to the DB. Should you take the singleton route, this can be a singleton object. Note that having a singleton DB connection can be slower than having multiple connections, because you can only run one query at a time. Something as simple and quick as a login will have to wait until other queries are finished, instead of running in parallel.
dunkelhelmut is offline  
Old 08-17-2004, 04:56 PM   #4 (permalink)
Insane
 
Adding to what RelaX says, you will always do something wrong the first time you program it. This is why there are multiple versions and programming techniques like refactoring. Once you learn how to do it, a better way is almost always found.
username is offline  
Old 08-18-2004, 02:46 AM   #5 (permalink)
Follower of Ner'Zhul
 
RelaX's Avatar
 
Location: Netherlands
Quote:
Originally Posted by username
Adding to what RelaX says, you will always do something wrong the first time you program it. This is why there are multiple versions and programming techniques like refactoring. Once you learn how to do it, a better way is almost always found.
So true... which is why OOP and spending lots of time on design is so crucial. In theory, if you do those perfect, then if you find a better way for a method or object to handle it's responsibilities, then you have to spend only a small amount of time to re-implement those methods and objects.

The real problems are changes in the design though. Even with proper OOP, if your design is seriously flawed, then it WILL mean lots of cursing and shouting at the pc trying to right the wrong and you'll probably end up with a real hackjob.
__________________
The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
- Nathaniel Borenstein
RelaX is offline  
Old 08-19-2004, 12:20 PM   #6 (permalink)
Upright
 
If you are looking to do this cross platform, you might want to consider Java, especially if you are interested in doing proper OO. And, if you are going to do that, you might want to look at building up from an existing framework, such as HiveMind .

Sure, you have some overhead in learning a new API, but remember the zen of Java: To make things simple, you must first make them complex.
bacon is offline  
Old 09-13-2004, 06:25 PM   #7 (permalink)
Upright
 
Connection Pooling

A technique that is used in industry for maintaining as few DB connections as possible is connection pooling. I program primarily in Java, so that is what I am basing this suggestion off of.

If you have a system that requires many small transactions to a database, very few of them are actually run simultaneously. You can have a pool of seemingly very few connections that get shared throughout the application. You have to be very careful to release the connections back to the pool EVERY time, especially when something fails. Otherwise you'll run out of available connections.

Most (all?) of the major web-based applications that are running out there use connection pooling rather than having dedicated connections for each transaction.
__________________
"Memo to myself, do the dumb things I gotta do. Touch the puppet head."
-TMBG
Tympanic is offline  
 

Tags
advice, design, oop

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 06:37 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360