Do you know you can earn heaps of $$ by answering questions on kodlogs, for more info contact us through feedback link at footer? We are Australian based web site and pay you for answering questions

  • Register
Welcome to Kodlogs Q&A, where you can ask programming questions and receive answers from other members of the community. For programmers, by programmers Kodlogs is an open community for anyone that does coding. We help you get answers to your toughest coding questions, share knowledge with your coworkers in private, and find your next IT dream job.
0 votes
4 views
Object Oriented Programming Concepts
by (580 points)  
reshown by

1 Answer

0 votes
So what is object oriented programming?Is it some kind of new technology? Is it just another programming language? or what is it?So object oriented programming to be simply said,         is a way of thinking.It's an approach to do software development.        Nothing more than that.So is that the only approach for programming? Is that the only available way of thinking in programming?Certainly not.So when we talk about programming,  programming really started with the invention of computers.right from the moment computers were invented, programming was there.because programming in it's very basic is nothing but giving instructions to the computer.and without instructions no computer will ever work.    So there was programming always.At the beginning of the computing era, the programming was usually limited to machine language programmingi.e set of instructions that are aimed at particular machine, particular processor to be honestUsually you will find machine language
code example like this:they are nothing but a sequence of bitsand imagine if you are now developing an Android application and I ask you to write the code in machine languagethat means you will have to write sequence of bits.     Will that really be possible?so that's what everyone thought and people moved on to next way of programmingand that was known as Assembly language programmingassembly language programming was a bit better than machine language programming in a sense that assembly language was more like English.This is nothing like English,  just a combination of          1's an 0's.You can't say what is this. This might be you know...this might be like: I am not gay (I am not BTW) or maybe
I do not know what it is.So it is hard to make sense of
this thing, right?but assembly language, If I were to give you an example it was something like this:ADD A to BMOVE B to CJUMP 9000.so this sentence basically means that: Add A to B, then copy value of B to C and then jump to instruction 9000so this is much better than the assembly
programming, right?Still this was not sufficient. Again I ask you the same question.Create an Android app, for let's say managing the billing system in a WalmartCan you write the code using these kind of
programming instructions?So again they came up with new thing that is:     Structured Programmingone instance of this, is procedural programmingand the most popular example of this would be:              C languageall those languages around 1970s or late 1960s were structured in nature.What you understand by structured in nature?they had these programming constructs that you and I use: if-else, loops, functionsThis is not very structured.if you want to implement looping in assembly language, it's like jump there then go back, something like that.whereas in procedural language you
have proper structured programming constructslike you know decision-making
constructs, looping constructs, functionsso this made programming
much much better in every regardand this was the most popular programming till you could say mid 90sso what went wrong? What is the problem with structure?Now I think my C programs are fantastically readable. They can achieve most of the thingsand people have told me that C is used in operating system implementation.So what's wrong with this?So the thing is; approach in C was to divide the big logic into set of functions.so overall the emphasis was on functionality, not on data.I agree that in C by creating lots of functions. program becomes more manageablebut that has a certain limit.if your program goes beyond, let's say a certain limitfor example 30,000 lines of code is crossedthen even if you breakdown that 30,000 lines of code into five functionslet's say four functions, then each of these
functions will also be about 8000 lines of code, right?So again even these
functions now become unmanageableyou can't hope to possibly debug a 8000 lines of code all at oncefuther more complicated thing is as I said earlier, the emphasis in structured programmingor you could say procedural approach
was on functions not on dataand if you ask any IT client of your company; What is the one thing about which customer really cares?it's not your functionality, it's about data.big corporations and big companies they all pay huge amount just to secure the data or to extract some meaningful information from the data.you can't you know, make data public or you can't possibly let data play lose.so when you divide your C program into five functions,first approach to share data amongst functions is to make data globalwhen you make some data global,
all the functions can use itbut the problem is, there is some data which is
common to these three functionsyou can declare it as global or you
could pass the data as an argument to three functionswhen you pass the same
data as an argument to three functions,it's wastage of memory, right?
We are passing the same data to three functions.so in order to avoid that we can declare it as globalthe problem with global is that; now there is this one more function which has no business with this databut still it has a free right to access that data because global can be accessed by any and every functionso this function might accidentally access this, because of the same name of naming conflict or something elseand it might change the value and this changed value will be affecting the functionality or other three functionsso data is not safebecause nobody thought about data that much. They were all about: function function functionso emphasis was on functionality not on dataThen people thought we need something else. We need something newand then there is this third reason. Which is I think is the most important reason of allthere was this gap between developers and software clients.so let's take this example:We have this sports complex in the neighborhood. They have these fantastic tennis courts over there,which I use a lotbut one problem that I found was;the courts needed to be booked manually by going to their office and that office was open only till 6pmsometimes because of my job timings I could only play late at night (tennis). Let's say from 10:00 to 11:00 pmso in that case I'm would have to make two rounds, two trips to the office.first to book the courts and then again at the night to actually playso I went to the complex to meet the owner and asked him:Why don't you develop an online booking system for your tennis courts?that will be really handy we don't have to make any trip to your office.anyone can book the courts from anywhere in the world. My brother could book it for me, right.He (The owner) was kind of interested in it so we started talking about how to develop that systemI was a technical person who was talking about:frameworks and we shall use this language we shall use that languagemaybe we could use you know this function, you know something like thatand that guy is totally non-technical. He doesn't understand even a bit of computing. Nothing at all, right.so he was talking like: we have 1200 active users, we have 15 security-men, we have 4 tennis courtswe have 5 lights, we provide tennis balls at
this rate, we have court booking timingsWe have this, we have that. We do this, we do that.Are you getting it? What I am trying to say here.I was more concerned about shall we use AngularJS? Shall we use PHP?Shall use JSP?  Shall we use Spring?and he was like: Users, Court, Booking, SecuritySee the gap in thinking. See the gap of
communication between us.In real life, we do not talk about functionality. We talk about objects, things.right now I am feeling terribly humid, you know.So what do I say? Give me air! Give me air!No. I don't say give me air. I say, turn on the fan or turn on the AC.In real life, we talk about objects. In order to get functionality, we seek objects.We don't seek functionality.so that's what that customer is talking about. He is talking about his thingsand I'm a developer so If I am only thinking about:How do I write a function for this thing ? How do I write local variables? How do I write global variables?that's not going to work. Our thinking should match.otherwise I might end up developing something which is of absolutely no relevance to him.so in  that case what was required was, if he says courtI should be able to write something in my code which is called as Court. Which represents this Court.If he says user, I should be able to write
something in my code which represents this user.if he says Booking, I should be able to write something in my code which represents this booking.I should be able to represent the real life objects in my code.I should not be only thinking about functions, local variables, global variables.If he says user, I should have user in my code. If he says court, I should have court in my code.and this is called as objects. I am creating objects in my code.and this way of programming, of trying to simulate real life things into your codeis called as Object Oriented Programmingnow that we have understood why this is required,  let's talk about the basics of  Object Oriented Programming.so now let's talk about the important aspects of Object Oriented programmingyou could say the major pillars of object oriented programming.first and foremost is object.so what is object?Object is a piece of code which represents a real life thing or real life entity for exampleas I was talking to that tennis complex owner he repeatedly talked about something called as Courtevery real life thing has two things:1) It has got attributes which we in English can call as characteristics2) It has got functionality, which in English can be translated to behavior.So court will have attributes like: color, type of surface, dimensionsWith regards to court what kind of functionality does that tennis complex provides?Let us say: doCourtBooking( )courtCleaning( )In programming we map attributes to
nothing but variables or let's say data membersand we map the functionality to functionsSo when we write an object in our code representing a real-life thing we write its variables i.e data memberswhich corresponds to attributesand then we write some functions which correspond to its behavior.The next thing is: ClassSo how we can define a class?I have read somewhere in some book: Class is a collection of objects. Which is so not true.What Class really is:It is a specification of an object.suppose you have been asked to create a student management system for a particular collegeNow obviosuly, the most important object in that system will be student itselfNow you have identified few things about student i.e his attributes and his behaviorfor example you're planning to store attributes:             roll number, name and markswhereas you're planning to store the
behavior that is curricularPerformance( )and extracurricularPerformance( )so where do you specify this, whatever we have decided i.e attributes and behavioryou specify that in classSo you create a class of Student. How do you do that?and then you specify student will have
three attributes: roll number, name and marksand it will have two functionalities curricularPerformance( ) and extracurricularPerformance( )so you specify here in the class of student that it will have these attributes and it will have this functionalityNow if somebody increases the marks of a studenthe (the student) increases his marks through hardwork or something or copyinghis curricularPerformace will changein another semester student's marks go down, because of his breakupthe
by  
...