Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
why we use separate classes for members and methods.... instead we can done all work in main()...
creating classes inherit it and make objcts...why????
Posted
Comments
Pheonyx 3-Sep-13 4:04am    
Google is you friend, there are thousands of resources explaining why alot of programming has moved to the Object Oriented approach which utilities classes, inheritance and a lot of other principles.

But in simple, let me ask you this...

Would you rather read through a 100,000 lines of code that jump all over the place but is a single main method. Or read through a more segmented but structured code base where functionality is grouped and made easily re-usable. Where the DRY principle is applied, and where each module/class etc has only the functionality it requires to operate?
Innocent910 3-Sep-13 4:09am    
tell me the reasons why we are using classes???
Pheonyx 3-Sep-13 4:10am    
Do your own research, it is not actually difficult to type stuff into google, I was making you think for yourself rather than do your homework for you.
Innocent910 3-Sep-13 4:15am    
m not geting the right answer from google thas y m askng u bro
Ian A Davidson 3-Sep-13 4:46am    
Search for "Object Oriented Programming", or "OOP". If you don't know what that is about, then you are quite right - don't bother using classes! (And I would wonder why you are using C# at all, which is founded on objects). However, if you get your head around OOP, then it can make writing different kinds of software a lot simpler and more understandable. Please, please, don't become like so many programmers I see, who simply stick "methods" into "classes" and call it OOP. So often they end up with a load of static functions (sub-routines, if you like) in placeholders which bear no relation to objects - basically, procedural programming, but even harder to understand because functions are spread all over the place.
Find out what OOP is about, and use it well; life will become much simpler for you and for anyone else who comes to maintain your code.
Regards,
Ian.

Have a read of the answers on here, and the following links:

http://csharp.net-tutorials.com/classes/introduction/[^]
http://msdn.microsoft.com/en-us/library/vstudio/x9afc042.aspx[^]
http://www.homeandlearn.co.uk/csharp/csharp_s10p2.html[^]
http://www.wikihow.com/Understand-Object-Oriented-Programming[^]
http://en.wikipedia.org/wiki/Object-oriented_programming[^]

The jist of why we use Classes and inheritance is because we are coding using the Object Oriented Programming approach which requires separation of concern as well as a lot of other principles. Start by looking at that and you will understand why classes are used.
 
Share this answer
 
Comments
Innocent910 3-Sep-13 4:26am    
thnx
Because it makes life simpler. Honest, it does. It may seem that it's a lot of work to go through to get to the same goal - and it is, for a very small project. But scale it up a bit...

Ignore computers, and let's look at making a physical object.

If you are making a pin, there are four processes: cut wire, twist end (to form a "blob" you can push), solder end to neaten the "blob", sharpen the pin. Easy. it;s trivial, and one man can do all of them, one after another. This is the Main() method way to do it.

But what if you are making a car? Would it be a good idea to start with a pile of raw steel, some rubber, some plastic and a bit of silicon? No - because the processes that you have to go through are enormously complex: just making wire means drawing the steel (or preferably copper) to thin it down, twisting it with other strands to make it stronger and flexible, then coating it in molten plastic to insulate it. Making a tire is also complicated: getting the banding laid down, moulding the right rubber around it...and don't get me started on the engine and management systems!

Instead, the various parts of the car are broken down into assemblies which are then assembled into large assemblies, and larger still until they can be finally assembled into a car and it can be driven. The individual assemblies don't need to know what they do in relation to other assemblies.

Software is the same. What works well for a trivial example becomes a huge PITA when you scale it up. Classes are like car assemblies - they know what they have to do, and they don't know about anything outside themselves, because it reduces the complexity if you do that.
 
Share this answer
 
Comments
Innocent910 3-Sep-13 4:21am    
thnx man
OriginalGriff 3-Sep-13 4:24am    
You're welcome!
abbaspirmoradi 3-Sep-13 8:12am    
Upvoted +5
Refer following link to clear OOPs concept

OOPs Concep
Basic concept
 
Share this answer
 
Here is your answer

why we use classes in c#[^]
 
Share this answer
 
Comments
Joezer BH 3-Sep-13 4:32am    
5ed!
[no name] 3-Sep-13 4:55am    
Thanks..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900