Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to improve my OOPS skills. Please guide me some links regarding that.

Say I have a product as entity. Now this can be inserted, edited or deleted by user in UI. User can further configure this product also.

So what can be ideal class design for that?

Thanks
Posted

Your question is vague, makes little sense and shows your lack of knowledge on the subject.
However, there are many useful resources on the web that can help you to better understand programming and OOP.
I am assuming you know the basics of programming. Creating variables, assigning values, creating class, methods, functions etc.
So OOP is not easy, nor easy to explain. I suggest you start doing some reading on the subject.
First, you must understand Object Oriented Programming[^]. Make sure you get Encapsulation[^], Inheritance[^] and Polymorphism[^]. They are the 'three pillars of OOP'.
After that you are far from there yet. The SOLID principles[^] are key to building robust and re-usable software.
When you get all of these principles you may start reading up on Design Patterns[^].

Once you've read that you're probably well on your way. Don't forget to practice, practice, practice!
Hope it helps and good luck! :)
 
Share this answer
 
Comments
sunder.tinwar 25-Feb-12 9:52am    
thanks for reply. I just wanted to know how anyone here would design a class which will meet above requirement and will be easily scalable in future.
Sander Rossel 25-Feb-12 10:02am    
There is no single class design that could do all that. It depends on techniques you use, libraries you use, quite possibly other requirements you have, maybe other tools you're working with... For example, if you use Entity Framework and binding you can actually do all that quite easily, without having a 'design'. Or you could abstract away your Entity Framework classes from your business and UI logic and create a more three tiered application design. Whatever works for you, your company, your customers... Overdesigning is also a design flaw.
So we cannot possibly give you an answer to that question.
Abhinav S 25-Feb-12 10:00am    
Fairly good answer. 5.
Sander Rossel 25-Feb-12 10:15am    
A fair thanks :)
Uday P.Singh 25-Feb-12 10:57am    
5+
First you need to define Interface with Add,Insert,Update and Delete Method.
All your different Product type can then implement that.

You can also create a abstract class called Product and have all your different product type inheriting the product class.

OOPS is just about thinking everything in terms of real object and applying the OOPS principle so that we can code in such a way that we can increase reusability and maintainability.
Below link is good article on OOPS. HeadFirst C# also is good book for understanding OOPS.
Introduction to Object Oriented Programming Concepts (OOP) and More[^]

You can also check Shivprasad Koirala's (MVP) nicely compiled videos on the same.
 
Share this answer
 
Comments
sunder.tinwar 25-Feb-12 9:56am    
thanks for reply, make perfect sense. Can you give any example regarding that.
Sander Rossel 25-Feb-12 10:07am    
Actually, that makes no sense at all! If I wanted another entity, say a sales order, I would have to rewrite all my Add, Insert, Update and Delete logic? Or use the Add, Insert, Update and Delete logic of my Product Class? Also, what about disconnecting your business from your data layer? A business object like Product should be unaware of any data stores and related actions. As it works in Entity Framework (an ORM) every Object Inherits from EntityObject and an ObjectContext keeps track of your entities. It is also in this ObjectContext that you mark Entities for deletion or add them.
The article you linked is good, but I think you haven't quite understood it yourself.
Rishikesh_Singh 25-Feb-12 10:25am    
@Naerling i think you are only thinking in terms of LINQ and i don't think Sundar has asked about LINQ or about ORM. He is just asking about applying OOPS concept. since he just told if he has Product how he can think about applying OOPS.I believe it might be easier to answer if we know his project requirement and how different entities are related.
If you have different product say Cycle,Car its not wrong in having a abstract class say product with all the common properties and method in Abstract class and overriding it in your actual Product like Cycle Car.

I agree when you say its very general topic but if you just give simple examples it will help more rather than saying its very wide topic.
Sander Rossel 25-Feb-12 11:24am    
I am not at all thinking in terms of LINQ (it never even crossed my mind!)... Or an ORM for that matter. It just doesn't make sense to have every business object have an Interface implementation for update, add and delete actions (imagine putting an Object in a list and having to call the Add method on the Object rather than the list!). If you are talking about database actions they should be abstracted away to your data-layer and you certainly shouldn't have to write a different implementation for every object. I merely explained very globally how the Entity Framework handles this for reference. Simply Implementing an Interface doesn't solve anything and is not even OOP by a long shot.
sunder.tinwar 25-Feb-12 14:15pm    
@Naerling what you are saying is also right, each business object can't implement interface and repeate same functionality.

Can you guys give generic example here.

My requirement is not specifically to any project. I just wanted to what are best possible way to do such kind of work. Like all companies follow extensive OOPS or just work to acheive goal. You can give me example of any other problem apart from this.

Thanks.
We can't answer that.
It's far, far too broad a subject - the answer is a book, not a TextBox!
 
Share this answer
 
Your question is actually too vast to answer easily.
You need to look at all principles of OOPS and then start implementing them. Very often you will realise that you don't even need to use all of these principles in your class, only some will suffice.

This comes with practice and there is no standard template for any of this. Few people can create the "perfect" OOPS class.
 
Share this answer
 
v2

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