Object Oriented Principles - NayiPathshala

Breaking

Total Pageviews

Loading...

Search Here

11/18/2017

Object Oriented Principles



Object Oriented Principles
1.Class - Class एक user defined data type होती है। ये C language में structure की तरह ही होती है। लेकिन classes में आप variable के साथ साथ उनसे related functions भी create कर सकते है जिन्हें बाद में objects के द्वारा access किया जा सकता है। एक class programmer को data centered approach provide करती है। Class के द्वारा आप variables और उनसे related functions को separate कर पाते है। इसके बारे में और अधिक आपC++ - Classes & Objects tutorial से जान सकते है।   
  2.Objects - जैसा की आपको पता है class एक user defined data type होती है। Class type के variables को objects कहा जाता है। Object के द्वारा आप classके variables और functions को access कर सकतेहै।   
3.Abstraction - Abstraction का मतलब होता है की end user को वही functionality show की जाए जिसकी उसको जरुरत है बाकी background functionality hide कर दी जाए। उदाहरण के लिए जब आप एक car को चलाते है तो आप सिर्फ clutch, gear और steering पर ध्यान देते है, engine किस प्रकार काम कर रहा है इससे आपका कोई मतलब नहीं होता है।  
4.Encapsulation - Encapsulation को data hiding भी कहते है। Encapsulation एक object oriented programming feature है जो data members(variables ) और उनसे related functions को bind करता है जैसे की class होती है। साथ ही encapsulation के द्वारा data और functions कोoutside access से protect किया जाता है। Encapsulation properties 3 level (Public, Private, Protected) का protection provide करती है। C++ में encapsulation classes के माध्यम से implement किया जाता है।    5.Inheritance - Inheritance object oriented programming का concept है जिसमे एक code को दूसरी जगह यूज़ किया जा सकता है। ये principle code re-usability implement करता है। उदाहरणके लिए आप एक class में create किये गए functions को दूसरी class मेंinherit कर सकते है ऐसा करने से आपको इन functions को दुबारा लिखने कीआवश्यकता नहीं होगी और आप इन्हें दोनों हीclasses के objects से access कर पाएंगे।  
6.Polymorphism- Polymorphismका मतलब एक नाम कई काम होता है। इसमें आप एक नाम से कई तरह के tasks implement करते है। C++ में polymorphism function overloading द्वारा implement किया जाता है जिसमें एक नाम के functions कोअलग अलग conditions में execute किया जाता है।   
7.Message passing - Object oriented programming में objects एक दूसरे से communicate करते है जिससे program real life condition को represent करता है।
 A Sample C++ program
#include
int  main()
{
cout<<"Hello Readers";
return 0;
}
इस उदाहरण को निचे समझाया जा रहा है।
1.सबसे पहली line में header file को include कियागया है। Screen पर output show करने के लिए आपको इस header file की जरुरत पड़ती है।
2.इसके बाद program का main method शुरू किया गया है।
3.cout function के द्वारा simple message को print किया गया है।
4.return statement के द्वारा function को return किया गया है।

No comments:

Post a Comment