How can I learn OOPS Concept, UML, Object Oriented Programming language(mainly C++)?
-
Hi I am Btech (Bachelor in technology ) final year Computer Science & Engineering student & I don't know any object oriented programming language. I am having difficulty in learning OOPS concept so i use just C for programming. I hate Java because of object oriented feature but i somewhat like C++ because it is similar to C. I tried to learn OOPS but I became frustrated because I didn't understand a single bit of it. Please suggest me easy way to understand OOPS concept deeply. Note : I not only want to remember the four basic concept of OOPS but also want to understand it deeply so that I can apply it in practical use. Thank You.
-
Answer:
Ask yourself how getchar in unix can execute any IO driver. How does the flow of control leave getchar and enter the keyboard driver for example? Does getchar know about the keyboard driver? (The answer is no.) The way this works is very simple, and is _very_ relevant to what OOP is. The UNIX operating system defines that an IO driver must have (at least) five functions. Open, close, read, write, and lseek. Every driver must implement those functions, and they must have the same signature. When stdin is set to a particular device, the pointers to those five functions are moved into a table within the stdin data structure. The getchar function then calls the function pointed at by the 'read' entry in that table. That is polymorphism. In C++ it is implemented with vtables. In java the implementation is different but analogous. You mentioned the four basic concepts. I presume these are Encapsluation, Inheritance, Polymorphism, and Identity. C is far more encapsulated than C++ or Java because in C you can put your public declarations in a .h file, and keep all the privates in the .c file. In C++ you have to declare some privates in a .h file, which means your users can _see_ them, even if they can't access them. A change to a private variable in a C++ header file causes all clients to be recompiled. A change to a private variable in C does not. So C is far more encapsulated than C++. This is also true for Java and .Net. These OO languages have _weakened_ encapsulation, not enhanced it. Inheritance in C is very easy. Consider the following two structures: struct point {double x,y;}; struct namePoint{double x,y; char* name;}; I can easily cast a namedPoint* to a point* and everything will behave well. This is basic single inheritance, and it is a common "trick" in C. C++ just made this a little more convenient. The concept of identity is no different in C than it is in C++, or Java. If you understand pointers you understand identity. So what we are left with is this. C++ gave us a little help with inheritance, and a lot of help with polymorphism. And, in the end, it's the polymorphism that counts. And here's why. Consider an application that has a main function that calls high level functions, that call middle level functions, that call lower level functions. The flow of control goes from main through the levels down to the lowest. Now, what direction do the _compile_ time dependencies (the #includes) run? Does main #include the high level functions? Do the high level function #include the mid level functions? If so, then the compile time dependencies point in the same direction as the runtime dependencies. However, now consider getchar. The getchar function DOES NOT KNOW about the io drivers. It does not #include the console driver. Yet it can still call it. Indeed, Instead, getchar depend on an abstract interface (open, close, read, write, lseek) and the console driver implements that interface. The flow of control is handled by using vector tables. Again, that's polymorphism. Polymorphism allow you to _invert_ the compile time dependencies so that they oppose the runtime dependencies. The power to do this means that you have absolute control over your compile time dependency structure irrespective of the runtime dependency structure. Now if you think about it, you'll realize that this is the basis for all plugin technologies. If your application can call a function it does not know about, that means the function can be _plugged in_ at runtime. If you've gotten this far, and you still hate OOP, then I fear that your hatred is irrational, and there is no hope for you. OO is not a religion, it is a very simple technology. OO is not a different way of thinking, it is a strategy for managing compile time dependencies.
Robert Martin at Quora Visit the source
Other answers
Hello, I can say why you find OOPS concept so difficult to understand. The reason is that you can easily visualize a program written in C , its flow and the decision making . The problem with OOPS based language is some times you find it difficult to visualize a program in terms of objects , their attributes and methods. The simple way to understand OOPS is to compare it with the nature. I will take an example of a class in oops. Now assume GOD to be a programmer so GOD created many classes like human beings, horses, various plants. So for a class of human beings you can associate height , weight , skin color as attributes of human class. Now GOD start creating you and me which are objects of human class. Just like any number of objects can be created of a class. What you and me differ in are the attributes. similarly two objects of a class differ in value of the attributes. Now why GOD created a human being class, because its now very easy to built all human beings by just creating objects with varying attributes. Hope this explanation could be just enough to provide you an insight into why we use object oriented programming and its advantages.
Sandeep Choudhary
Although you hate it, I suggest to start with Java as the syntax helps you to grasp the logic behind OO better. C++ is more flexible, which does not necessary mean a better starting point. The fastest way to learn the principles is via pair programming and reading code. Focus on the SOLID principles and try to recognize them in exiting code. Finally, remember that writing simple code is one of the hardest things to do, so always ask yourself the question: Why?
Eelco Meuter
Related Q & A:
- How can I learn hadoop through projects?Best solution by globalknowledge.com
- How can I learn how to do stick figures or animated stuff online free?Best solution by Yahoo! Answers
- How can I learn how to sing?Best solution by Yahoo! Answers
- How can I learn how to invest?Best solution by Yahoo! Answers
- How can I learn more in the French language?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.