Classes in Object Oriented Programmimg | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

Classes in Object Oriented Programmimg

I'm an OOP noob. Pretty much every beginner tutorial I see on OOP uses animal -> mammal -> cat type example for classes and inheritance. This is helpful to get the simple idea ... but, I'd like more concrete and realistic examples to get an idea of what I'd really use it for. Can you help provide me with real life examples of class and inheritence that I might expect to come across in a professional programming situation? I'd love to see examples of any kind that are used in the real world. Thanks!

22nd Feb 2018, 4:55 PM
JMQ
JMQ - avatar
9 Answers
+ 7
thank you @Segev Elmalech
23rd Feb 2018, 6:46 PM
JMQ
JMQ - avatar
+ 6
@sneeze, @Bagshot, @Insight thanks all of you for taking the time. these were helpful!!
23rd Feb 2018, 6:14 AM
JMQ
JMQ - avatar
+ 5
Scientific Example: We would like to work with big integer numbers and define special functionalities for them.so we should create a class and add properties and methods to it. Game Example: Imagine we are thinking about a game with a ball doing fancy stuff. again we create a ball class and implement for example some formulas for its movements. Also about inheritance, it's better to define a basic ball class and then for different types of balls, we will change or add some details. If these are not sufficient, tell me to explain more.
22nd Feb 2018, 5:33 PM
Insight
Insight - avatar
+ 5
how it can be called derived class
24th Feb 2018, 9:59 AM
آفریں فاطمہ
آفریں  فاطمہ - avatar
+ 2
One way to look at classes is if they are blueprints to create objects. So if I was writing a blog engine, for example, then I could write and read information from a database using a class like this: public class BlogPost { public string Title { get; set; } public string Content { get; set; } } This class has the string properties "Title" and "Content". As of yet, these properties have no values. So to use this class I would create an object (blogPost) that has access to these properties: var blogPost = new BlogPost() { Title = "My first post.", Content = "Some content for testing." }; Now my object has some values -- in this case manually entered strings, but in real life, probably retrieved a database -- they can be displayed in a UI, for this example it's the console: Console.WriteLine(blogPost.Title.ToUpper() + "\r\n" + blogPost.Content); OOP makes handling data clean and efficient. https://code.sololearn.com/cQ7U4rWZ6SPn
22nd Feb 2018, 9:39 PM
Bagshot
Bagshot - avatar
+ 2
A college example : Start with students, teachers. Both deriving from a people class. In the people class age and address is defined. In the student class study and grades are defined. In the teacher class wage, payment, competents are defined.
22nd Feb 2018, 10:18 PM
sneeze
sneeze - avatar
+ 1
I have an article page on my app. The article could be with different types like article with text only or image only. So I have created an Article class as super and class for each type as subclass because there are common properties like type and different properties like images or texts.
23rd Feb 2018, 3:06 PM
Segev Elmalech
Segev Elmalech - avatar
+ 1
Rt @Viktor
5th Apr 2018, 3:51 AM
Rafael A. Reyes
Rafael A. Reyes - avatar
0
i like real world application examples: abstract class Action{ protected $_response =“”; abstract public function processAction(); public function getResponse(){ return $this->_response; } } class PlaceOrder extends Action{ public function processAction(){ $this->_response = “order placed”; } class CancelOrder extends Action{ public function processAction(){ $this->_response = “order canceled”; } now you can ecapsulate all your logic for each action. you can easily run any action because they all share the same methods, and you can easily add actions.
8th Dec 2018, 3:50 AM
John Anderson
John Anderson  - avatar