Hi all,
I'm a C# programmer, I have a big problem with OOP, all what I know is
fundamentals and concepts but I'm bad in applying that in practical and real
programming
I need your help to tell me how to enhance my practical level and how to be a real OOP and good programmer in general
Is there's specific websites or programms I have to write or what ? Give me examples, please
Thanks in advance,
Habeba KhaledPosted Dec 13, 2007, 4:50 AM
Wow, great reply
I like what u said, I learned good from that
Thanks alot
Posted Dec 11, 2007, 1:37 PM
Take this example:
public class Ball
{
//Good rule of thumb, always make these private and
//access them via "smart fields" a.k.a. properties,
//as show below.
private string color;
private string material;
//The constructor is used to provide default
//values or passed parameters to a new ball.
public Ball()
{
this.color = "Black";
this.material = "Rubber";
}
//Methods to manipulate the ball
public void Throw(string location)
{
//Use the location to define where the ball
//should now be
}
//Properties are basically special variables
//The ball has a color, and it is made of
//a material
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public string Material
{
get { return this.material; }
set { this.material = value; }
}
}
The ball is a "virtual" object, it contains methods to manipulate it, and it contains characteristics, or properties, of the ball. If you wanted multiple balls (save the evil thoughts :P ), you could do something like this:
public class MyShapes
{
List<Ball> balls = new List<Ball>();
//Create a strongly typed list containing
//two balls (the norm)
balls.Add(new Ball());
balls.Add(new Ball());
//Now you can access their properties and methods:
balls[0].Color = "Yellow";
balls[1].Material = "Foam";
//Throw the first ball
balls[0].Throw( /*MyLocation*/ );
}
A TON more could be done, but this is the most base example. Just keep this in mind, objects are created using encapsulation. They contain properties, methods, and fields that belong to the object (or the class in the case of static members) and can be used to manipulate the data in the class or the class itself. Once you get into the mindset that all classes are really objects like the Ball above, then you can expand your knowledge by using inheritance and polymorphism. Im not sure just how much experience you have, so Im just starting from the ground up :)
Habeba KhaledPosted Dec 10, 2007, 3:58 AM
Thanx again, Maha
Of course I know that I can easily get thousand of topics in OOP
but as I said before I just care about the practical part, examples, real projects .. etc
The links u gave me is really good, hope they will increase my experience and
enhance my practical level
Thnx dear,
Posted Dec 9, 2007, 8:02 AM
There are many articles about Object-Oriented Programming in the C# Corner website. If you type “Object-Oriented Programming” in the search box of C # Corner you can get it.
Also there are many e-books available in similar title in Apress website (http://www.apress.com/).
Habeba KhaledPosted Dec 9, 2007, 3:56 AM
Scott,
Thanks also, very good explanation of OOP :)
Thanks all guys
any other links or advices ?
Habeba KhaledPosted Dec 9, 2007, 3:46 AM
Maha,
Thanks alot for the link, It's really useful :)
Scott BradyPosted Dec 7, 2007, 6:28 PM
Hope this link will help explain things a little for you
http://www.developer.com/net/csharp/article.php/1465681
Kind Regards
ScottyB
Posted Dec 7, 2007, 4:26 PM
http://www.java2s.com/Code/CSharp/CatalogCSharp.htm
Language Basics section of the above website has many C# examples. See whether
these examples do any help.