c++ my second year start/
handy collaborations-
program can be organised in one of the two ways : "around its code"(what is happening) and "around its data"(who is being affected).
STL(standard template library) is one of the main features of c++ created by alexander stepanov.
oop (object oriented programming) took the best ideas of structured programming and combined it with several new concepts.
structured programming-
->organised around code (code acting on data)
eg. c program is defined by its functions any of which may operate any type of data. whereas ........ in
OOP-
-> organised around data(data controlling access to code)
-> data type defines precisely what sort of operations can be applied to that data
-> oop languages have three traits in common and they all support its principles:
<Encapsulation>
<Polymorphism>
<Inheritence>
1. Encapsulation-- mechanism that binds together code and data it maipulates and keep it safe from outside interference. In OOP , code and data are combined in a way that a self contained black box is created. when they link in this fashion
an "object" is created.
so, object can be defined as -
-> self contained black box of code and data protected from outside
interference or misuse.
->device that supports encapsulation.
-> n further we gonna know that it can be " a variable of user defined data
type".
within object, code ,data or both may be private or public.
private> means accessible only by the other part of the object and not
accessed by the piece of program that exists outside the object.
public> means other parts of our program may access it even it is defined
within an object.
so, for this an object must be a variable of a user defined type.
>strange to think that an object that links code and data can be thought of as a
variable.
>each time we defined a new type of object , we are creating a new data type.
2. Polymorphism--
-> follows " one interface , multiple methods "
-> it is the attribute(abstraction of the characteristics of an entity) that allows
one interface to control access to a general class of actions.
let us start with an example -
when a thermostat is set to 70 degrees , no matter what your furnance is gas,oil or electric the temprature's not gonna change(the interface is same)
from programming - we have three different types of stacks for integer values ,
character values and floating point values. Because of polymorphism , we can define one set of names push() and pop() that can be used in all three stacks. In
our program we'll create three specific version of these functions but names of them will be same.
compiler automatically select the right function based upon the data being stored. so interface to a stack - push() and pop() will remain same no matter which type of stack is being used.
The first oop languages were interpreters , so polymorphism was supported at the runtime but in c++ both runtime and compile time polymorphism are supported.
3. Inheritence-- is the proces by which one object can acquire the properties of
another object. it supports the concepts of classification.
example: food->fruits->apple->red apple. without it each object would've to
define explicitly all its characteristics.Through the use of classification we
we only need to define those qualities that make it unique within its class.
----------------------------------------------------------------------------------------------------------------------------------
> in c++ you may declare any variable at any point of time within a block not just at the begining (as in C) , its up to you.
> since much of the philosophy behind c++ is the encapsulation of code and data , it make sense that you can declare variables close to where they are used.
>"default to int" rule was dropped from c++ a couple of years ago, during standardisation.
> the purpose of namespace is to localize the names of identifiers to avoid name collisions.
handy collaborations-
program can be organised in one of the two ways : "around its code"(what is happening) and "around its data"(who is being affected).
STL(standard template library) is one of the main features of c++ created by alexander stepanov.
oop (object oriented programming) took the best ideas of structured programming and combined it with several new concepts.
structured programming-
->organised around code (code acting on data)
eg. c program is defined by its functions any of which may operate any type of data. whereas ........ in
OOP-
-> organised around data(data controlling access to code)
-> data type defines precisely what sort of operations can be applied to that data
-> oop languages have three traits in common and they all support its principles:
<Encapsulation>
<Polymorphism>
<Inheritence>
1. Encapsulation-- mechanism that binds together code and data it maipulates and keep it safe from outside interference. In OOP , code and data are combined in a way that a self contained black box is created. when they link in this fashion
an "object" is created.
so, object can be defined as -
-> self contained black box of code and data protected from outside
interference or misuse.
->device that supports encapsulation.
-> n further we gonna know that it can be " a variable of user defined data
type".
within object, code ,data or both may be private or public.
private> means accessible only by the other part of the object and not
accessed by the piece of program that exists outside the object.
public> means other parts of our program may access it even it is defined
within an object.
so, for this an object must be a variable of a user defined type.
>strange to think that an object that links code and data can be thought of as a
variable.
>each time we defined a new type of object , we are creating a new data type.
2. Polymorphism--
-> follows " one interface , multiple methods "
-> it is the attribute(abstraction of the characteristics of an entity) that allows
one interface to control access to a general class of actions.
let us start with an example -
when a thermostat is set to 70 degrees , no matter what your furnance is gas,oil or electric the temprature's not gonna change(the interface is same)
from programming - we have three different types of stacks for integer values ,
character values and floating point values. Because of polymorphism , we can define one set of names push() and pop() that can be used in all three stacks. In
our program we'll create three specific version of these functions but names of them will be same.
compiler automatically select the right function based upon the data being stored. so interface to a stack - push() and pop() will remain same no matter which type of stack is being used.
The first oop languages were interpreters , so polymorphism was supported at the runtime but in c++ both runtime and compile time polymorphism are supported.
3. Inheritence-- is the proces by which one object can acquire the properties of
another object. it supports the concepts of classification.
example: food->fruits->apple->red apple. without it each object would've to
define explicitly all its characteristics.Through the use of classification we
we only need to define those qualities that make it unique within its class.
----------------------------------------------------------------------------------------------------------------------------------
> in c++ you may declare any variable at any point of time within a block not just at the begining (as in C) , its up to you.
> since much of the philosophy behind c++ is the encapsulation of code and data , it make sense that you can declare variables close to where they are used.
>"default to int" rule was dropped from c++ a couple of years ago, during standardisation.
> the purpose of namespace is to localize the names of identifiers to avoid name collisions.
No comments:
Post a Comment