I make an app in c# with windows forms and all my code is behind the window code, so i have for now 2500+ lines of code and some of my collegues say to use classes to divide the code by functionalities but i don't find a purpose in that because everything will be made public and so on. None of them know to explain me why it is the best approach, but just give me vague hints like : "if you do a modification somewhere your other functions will crash" and i don't know how that is possible... I searched and find a keyword "partial" so what should i do? Should start learning classes and so on?
-
5you should learn OOP. – Bgl86 Sep 11 '15 at 10:37
-
3If you're asking this question, please don't use partial classes! – James Sep 11 '15 at 10:49
3 Answers
You need to go right back to the basics, and not be put in charge of writing an application by yourself. Ask your employer to excuse you from your responsibilities whilst you learn how to do them, you're just digging yourself a deeper hole with every line of code you write at the moment.

- 936
- 7
- 14
-
I know pretty much of the basics and this app is just for me to use and i don't understand why i should apply the principles of oop here... – Grigore Marian Sep 11 '15 at 10:42
-
3Testability, readability, maintenance, general good habits, to avoid the mockery of your peers - pick any of the above. – Callum Bradbury Sep 11 '15 at 10:43
-
3If you are in the mind of "I know what I should do, I know OOP, but I dont want to do it" then there's nothing this site can help you with. Your question is irrelivent, You are knowingly doing the wrong thing, and are asking why you shouldn't when you already know why you shouldn't. – Skintkingle Sep 11 '15 at 10:47
-
It's not like i don't want to do it, it is more i'm not convinced i have to do it, i am thinking actually to modify the app and i just wanted to hear some opinions but thanks for the feedback guys ^_^ – Grigore Marian Sep 11 '15 at 10:56
-
You don't have to do it, it's your choice, but you definitely come across as not wanting to. I question how your colleagues were unable to convince you, as it really isn't that complex a question, unless you're actively looking for reasons not to. Either way good luck I guess – Callum Bradbury Sep 11 '15 at 11:07
-
It is in my interest to study because i'm an intern and the thing is the app works, no one will look through my code and so on, this question was just for me to see some arguments from more experienced programmers :D Thanks for the feedback and have a good day ! – Grigore Marian Sep 11 '15 at 11:16
A class is designed to be a reusable block of code. the class is for relating functionality together. the class is for classing things into a particular set of instructions.
This is the idea and reasoning behind OOP.
Consider a Road, a Road can have 0 to x cars on it. All of the cars can "drive" and they can "turn" they can even leave the road and join another road. They work together but are not one and the same thing. A car can drive but a road cannot. You dont want to have a "Road" class with 900000 methods for different cars all with their own drive methods and "leave road" method... You have 1 "class" which you can create multiple times into different occurances of that class, which may or may not be on that road.
Not to labour the analogy but it's a very popular one. Your code is not all doing the same thing even if you think it is, You have to scope your opinion correctly. You may have file access code next to UI code next to Business logic code next to network communication code. they are all pieces in the puzzle of "My Application", but within "My Application" they are not doing the same thing. It is with this kind of thought that you need to move forward and not with "It's just me, Writing this same application, it all goes here"

- 1,579
- 3
- 16
- 28
The main answer for which you should divide your code into classes is code reusability. You could greatly benefit from techniques of object oriented programming such as inheritence, polymorphism and so on.
Moreover, the time invested in learning Object oriented programming is a time invested in you, and for your greater understanding of different programming languages or frameworks which you may be using in the future.
Although you could do this project all by yourself and without using any classes, I strongly recommend you to try and learn OOP programming.
PS: C# is an object oriented programming language, which means that all object and variable type you may be using are classes!

- 63
- 7