473,624 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

maxx233
32 New Member
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 1907
RedSon
5,000 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
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
3017
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 example dsParts.xsd and including that in the data tier. I then will create a class that looks like this Public Class CPart Inherits dsParts
11
9239
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
136
9296
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
14
3125
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... (both are "Pascal Case" with no leading or trailing qualifiers). For example... I'll be modelling something, e.g. a computer, and I'll
5
3187
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. 1. I can create a common module like common.vb in my project and put all the functions in there. 2. Create a utility class and create the common functions as shared
10
3436
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 somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
26
3627
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 C++ Standard Library : A Tutorial and Reference (most of it) Exceptional C++
16
2791
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 efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
17
3028
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 else? The reason for this question is that I had an assignment in which I was
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.