Solved

looking for basic object oriented examples

Posted on 2013-10-29
4
279 Views
Last Modified: 2013-11-07
Basic example, not looking for very complex

The only basic example I can find is that one house uses a blueprint of many houses.
I am looking for different examples

Real examples of projects you have done

What was a class

what were methods

what were properties
0
Comment
Question by:rgb192
4 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 39610841
Hi

Class - say 'Human' as a class
            There are variety of human in earth varing in their colour in skin, hair, eye etc, But basically they have red blood, same organs etc. Those common characters can be called as a Class .

Properties - Color, Height , Weight etc are properties

Methods - Say 'Question' as a method. If you ask the human a question (input parameter) , he/she will analyse your input (question) and will respond based on the knowledge (algorithm of that method)

Class is a group of all the common properties and methods

Hope you got some idea
Raj
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 39610887
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39611530
Back when I was learning OOP (when C++ was the 'new' language), the OOP book gave something like the following as a basic example.

Start with a Class named 'Shape'.  Give it properties of 'CenterX', 'CenterY', and 'Color'.  Add a virtual method 'Draw()'.

Derive from 'Shape' classes like 'Square' and 'Circle'.  Each derived class will have additional properties:
Circle will need a property of 'Radius'.
Square will need a property of 'Length'.    

Write the 'Draw()' method for Circle and Square.

Now, you can create an array of 'Shape' objects.  But the 1st shape can actually be a 'Square' while the 2nd shape can actually be a 'Circle'.  Using Shape[0] and Shape[1], you can update the color or location (CenterX, CenterY) of the object, because these are the common 'Shape' properties that you can update without having to know the details of the derived class (like the radius of the circle or the length of one side of the square).

Because the base class 'Shape' defined the Draw() function, you can call things like Shape[0].Draw() and Shape[1].Draw() without even knowing what type of shape these objects are.  Thru the power of polymorphisim, Shape[0].Draw() will actually call Square::Draw() while Shape[1].Draw() will actually call Circle::Draw().

This example really comes more from C++, so things might be a touch different for C#.  But the concept is still the same in any OOP language.  Even go old Visual Basic has some of these OOP properties... like the fact it could implement the polymorphisim described above (it just didn't support inheritance - so you had to do a bunch of Copy-n-Paste to simulate that).
0
 

Author Closing Comment

by:rgb192
ID: 39629613
Human properties attributes
human actions ask a question

shapes properties radius length
shapes actions draw

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now