Thursday, October 13, 2016

Abstraction and Encapsulation

good morning good afternoon good evening at whatever time you're looking at this
video at whatever time you doing this video
basically this whole video series i have made for the only one purpose that are
I want to show optically programming an actual practical sense implemented in
shisha
so that's my whole gist of this video right
so the first important thing is that why have I come up with this video images
that are so many videos available out there are so many tutorials available on
the internet which talks about objectivity programming
basically I've seen that you know most of fifty percent of the tutorials
I'm not saying that there are not good to turn that there are really good tools
are you going to programming but you will see that you know fifty to sixty
percent of the students talks about cars and reels and you know and trees and
then father and son and acceptor and they talking terms of real world but
when it comes to actually implementing these concepting sheesh our body
language like Java
uh that's a little trouble little bit of a different understanding you need to
keep so that that little bit of different standing is what this video
we'll talk about and second this video will emphasize more on practical is it
will show you actually the source code of how logical pencils are implemented
so let's first just put a one-line definition of why do we need object into
programming
basically when we talk about source code and when we talk about any technical
implementation like any sharp are going to be to any kind of a coding in c sharp
so we talk in terms of data and I you know we're talking terms of all you can
say purple logic programming logic we talk in terms of service connections the
top in terms of if conditions why conditions
so we talk in terms of more logical and technical words
now what happens is it is good to talk to us finally you have to definitely
write code for it but if you can organize this whole chord in terms of
objects of real world then it becomes very easy to understand and easy to
maintain the source code
in the sense that you know if you like the if condition or three or four times
if conditioning ok if this is this is this is and if this is and the other
than that you just say okay this is this object right
so if you try to map your source code in terms of real world are you design your
source code in terms of real objects of the world then it becomes very easy to
understand if tomorrow you are leaving the company you can give a very nice
hand over to a new personal and and go ahead with a new career
so in a sense you know the the school becomes independent of a developer
so you can see that object to programming is approach where you
organize your source code you design your project in in terms of real world
real object royal so that's that's the key concept you should always remember
object into programming
ok now that many principles around this programming and the four or five
principles like abstraction inheritance i'll just say the words and then we will
see that how these are implementing projects abstraction inheritance and
calculation polymorphism index of extra pop so what we'll do that we first start
with the word abstraction is a plan principal object of programming so
abstraction in one line we should say is that when we expose what's necessary
because the main reason why are you going to programming came into our came
in two languages like C sharp and darker it is to remove complexity
you know to think in terms of the real world and remove complexity
so the first principle which is about which of our objective programming that
is abstraction says that only show what's necessary don't show unnecessary
things right now there's elements will call it an encapsulation
it says height complexity right so i have given both of this in the only one
video
I'm trying to spend most of this concept in one video because the compliment each
other lock abstraction says surely necessary
well in captions and goes a bit negative or it is just a negation of thinking of
abstraction that is hide complexity
right but these words are still very much different and we'll see that white
is different right
so let's first see ok let's first damage how do you implement abstraction jail
project like here's a simple invoice header class now this invoice had a
class of this in right center
when it wants to insert into the school server database right
it needs to call the update to the latest matter and what it calls a little
bit of his misery does series of things like it adds invoice first to the
database gets this reference number
after that it adds all the child's of invoice details so a couple of steps
which is dust right now if a user who is externally using your object or using
your class right
if you tell him that okay you know what you need to do is that you need to first
get the first number you need to add a child in 24 days you know to do that and
then I want to tell you is that you know i'm gonna say i just show him only one
method and that is updated database
so in a sense I just tell him if you want to use my invoice header component
you just call update your database so now your end user only knows the single
operation and all these operations are and calculated from him
are there hidden from it because these are complexities which you can take care
in your class and what is exposed outside is abstraction that is only one
method which the user needs to call right
so you can see that abstraction actually tries to show to the user what is
necessary
while and calculation actually our hides the complexity in the sense in other
words i'll tell is that and calculation are an abstraction they basically
complement each other right in the sense in one place to talk about what to
expose so this is more for design abstraction is more for design you when
you design a project you should think about that
what is the minimum the user should need right and encapsulation is how can you
hide those things from the user
now how do you implement and calculation she shot basically you declared your
methods that private
are you glad you are
objects and entities that you want to hide from the real world in the real
world as private right so you're the implementation which have shown the same
invoice had a class which i was discussing just on the video on the
slide right and you can see that the invoice have a class basically has that
method
let's scroll to that yeah
so here's this update the database right and i have declared the other two ones
as private
why I have to tell us climate because i want to hide that
and this is scholars encapsulation and i'm just showing what is necessary that
is updated database to my external world or to my external client is going to use
this component only the necessary method that is updated APIs so abstraction you
can see as a tool in one liner is nothing but to show what is necessary
now when i try to you when i'm using this object right now if you see my
client when I say client i'm going to say that I want to use this component
you will see that in the button click right let me go to my button click PT
and add in works you'll see that my client just needs to all updated
database so we just need to create a object and just needs to call only one
measure of your database so this is an abstraction in a sense i'm just showing
what is necessary
so anybody who are using my invoice had a class doesn't need to talk about
anything else other than to think about anything else
he only thinks about the single method and what I've done is that is a
component that is the invoice header as a component has taken up all the being
to hide that complexity from the client that is my aspx file and you can see
more of these methods are private a lot if you do a dark right
if you try to see in the intelligence you will not see these two things that
is
I'd get Adam getting voice number and add the child
these two are my headaches so if i go there and if i see i won't see those two
private method life because that's nothing but it is it is in calculation
or it is hiding the complexity and abstraction is all about showing what
what is necessary
so when you start designing a project first thing that what you want to show
to the user so that you can make an object simple and likes remember
simplicity is what object oriented programming is all about
that's why you're going to programming was introduced in real world
all right i hope that i was able to explain abstraction and encapsulation in
the first time it was very difficult to are basically understand of different
programming for newcomer but you know as you start thinking in terms of classes
and objects and in abstraction and inheritance it becomes much clearer and
it becomes much more maintainable and fun to do your programming and coding