473,383 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

C# App - Best practices question: OO design/code placement

maxx233
32
Hello all,
I'm new to OO design and have a question regarding where I should place some code. Here's a simplified situation:

I'm making an app to do create, submit, and track employee reviews within our organization. Should I have a class called Review, with properties for things like "review date", "employee being reviewed", etc?.. And methods for things like submit(), generateReport(), delete(), etc? I don't really think I *need* an object of this type, I don't need to pass it around within the program, I can't think of any reason I'd ever use this sort of thing later in a different program... it just needs to be submitted straight to a DB from a specific form within my app. And then specific information from that DB will later be used to fill in other parts of later forms.

Should I still make an object just for the sake of feeling more like an OO programmer, or should I be approaching it from an angle I'm not seeing that makes more OO sense? Or should i just do it the way that makes sense to me now by not creating an object, and just taking the info directly from the text fields in my form, straight to a DB, and later pulling the exact info I need from that DB to whichever form needs it at the time?

Also, whichever method I end up using to submit the review to a DB (either straight from text fields or into an object first that has a submit() function), should I hardcode all my DB code in every method in my app that ends up needing it? My last project I made a static DB(string query) method in app.Program.cs that had all my DB code and took a string as a parameter, which it then used as a query string with the DB code it had to make the connection and execute that query string. I don't know if that's what people normally do, if it's bad practice, etc. etc. ... I know that I don't like that way of doing things because if I were to create a Review class, it wouldn't be self contained - it would have to call to app1.program.DB(string) to function, so if I ever used that class in another app it wouldn't work unless I filled in the missing portion of that app's Program file. But I *do* like this way of doing things because if I need to change something in the way my program accesses the DB (or *which* DB it accesses), it's in a central location and takes 5 seconds to change the entire way the program handles DB work. Is there a better way? Im interested to hear people's thoughts who have more experience than I when it comes to oo design. Let me know what you think, or if I didn't explain things well enough. It's much appreciated, thanks!

Maxx
Dec 10 '07 #1
4 1894
RedSon
5,000 Expert 4TB
Hello all,
I'm new to OO design and have a question regarding where I should place some code. Here's a simplified situation:

I'm making an app to do create, submit, and track employee reviews within our organization. Should I have a class called Review, with properties for things like "review date", "employee being reviewed", etc?.. And methods for things like submit(), generateReport(), delete(), etc? I don't really think I *need* an object of this type, I don't need to pass it around within the program, I can't think of any reason I'd ever use this sort of thing later in a different program... it just needs to be submitted straight to a DB from a specific form within my app. And then specific information from that DB will later be used to fill in other parts of later forms.

Should I still make an object just for the sake of feeling more like an OO programmer, or should I be approaching it from an angle I'm not seeing that makes more OO sense? Or should i just do it the way that makes sense to me now by not creating an object, and just taking the info directly from the text fields in my form, straight to a DB, and later pulling the exact info I need from that DB to whichever form needs it at the time?

Also, whichever method I end up using to submit the review to a DB (either straight from text fields or into an object first that has a submit() function), should I hardcode all my DB code in every method in my app that ends up needing it? My last project I made a static DB(string query) method in app.Program.cs that had all my DB code and took a string as a parameter, which it then used as a query string with the DB code it had to make the connection and execute that query string. I don't know if that's what people normally do, if it's bad practice, etc. etc. ... I know that I don't like that way of doing things because if I were to create a Review class, it wouldn't be self contained - it would have to call to app1.program.DB(string) to function, so if I ever used that class in another app it wouldn't work unless I filled in the missing portion of that app's Program file. But I *do* like this way of doing things because if I need to change something in the way my program accesses the DB (or *which* DB it accesses), it's in a central location and takes 5 seconds to change the entire way the program handles DB work. Is there a better way? Im interested to hear people's thoughts who have more experience than I when it comes to oo design. Let me know what you think, or if I didn't explain things well enough. It's much appreciated, thanks!

Maxx
Maxx,

I think you have the main idea behind OO programming. However it does not make sense to make an object just because you can. If there is a need for the object then you should make it.
Dec 10 '07 #2
maxx233
32
Thanks! I was kinda figuring, but I see so much about emulating real objects (a piece of paper report) with code objects that I just wasn't quite sure if good design dictated to do it anyway.

Any thoughts on the DB code placement? Inside each method that needs it or centrally? If centrally, then is Program.cs the best place to put it, or is there a better way? Thanks a bunch!

Maxx

Maxx,

I think you have the main idea behind OO programming. However it does not make sense to make an object just because you can. If there is a need for the object then you should make it.
Dec 10 '07 #3
RedSon
5,000 Expert 4TB
Thanks! I was kinda figuring, but I see so much about emulating real objects (a piece of paper report) with code objects that I just wasn't quite sure if good design dictated to do it anyway.

Any thoughts on the DB code placement? Inside each method that needs it or centrally? If centrally, then is Program.cs the best place to put it, or is there a better way? Thanks a bunch!

Maxx
You can put your DB code in each method but if you are putting several copies of the same code in each method then that would be a good candidate for making a new helper method.

Let your program dictate its form a structure. Don't make an object unless you see a need for it. Don't make a method unless you see a need for it. When you are working with small programs you can work from this sort of bottom up design. Small programs are great because you can try lots of different things and it won't take you weeks to refactor the code. For example you can build the entire program in one main method, then you can look at it again and think of ways to improve. So now you have a program with a few methods, then you look at it again and think, hey I could encapsulate this in a couple classes. So then you refactor yet again. Eventually you will get an eye for these kind of optimizations.

This type of iterative improvements will be a very big help to you when it comes time to design a complicated system months before any coding actually begins. This is why software people get paid so much; if you can become a good designer it's like becoming a good architect you will be able to create this complicated and gigantic thing that won't fall down and kill people.
Dec 11 '07 #4
maxx233
32
heh, good analogy :) Thanks a lot, I appreciate it!

Maxx
Dec 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
14
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them......
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
26
by: puzzlecracker | last post by:
It'd be interesting to compare the learning practices of c++ practitioners. I'll start with mine The C++ Programming Language C++ Primer Effective C++ More Effective C++ Effective STL The...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.