In: Computer Science
Instructions
To make the most of programming, you need to deeply understand the principles that underly the paradigm that you are using.
For this task you must explain the principles of object oriented programming and relate these to the programs you have created.
Note: Explain is more than just a description, you want to convey a deeper understand- ing that can be achieved with a simple description. Try to relate the principles together and express the depth of your understanding.
Tip: A deep explanation does not need to be a long one. Aim to convey your under- standing in a concise fashion.
Create an article / blog post / letter to a friend / comic / movie / podcast / etc that explains the principles of object oriented programming, as you understand them, and outline what qualities you should look for in good object oriented programs.
Keep it to about 1 or 2 pages of text (if text based)
Videos or podcasts should be kept as short — but still demonstrate depth of understand- ing.
Creativity will be valued
Tip: Including references to textbooks (not wikipedia) or research papers can help you strengthen your explanation. Remember to reference other peoples work.
Make sure your explanation covers the following:
Concepts and Principles Programming Artefacts |
|||
Abstraction |
Encapsulation |
Class |
Method |
Inheritance |
Polymorphism |
Object |
Fields |
Roles |
Responsibilities |
Interface |
|
Collaborations |
Coupling |
||
Cohesion |
Relate these to programs you have written in this unit.
1. Abstraction : In simple words, abstraction means to hide the internal details and to show the features of the program. Let's take an example of a car, the driver will be able to handle the steering wheel, break, clutch, accelarator pedal, but he won't be able to see how the engine works, how the horn blows and how the interior mechanism works, because its waste of knowing for a driver, his job is to just drive the car from one point to another. Similar is the case with the users who wants to utilize the softwares and applications, they will only deal with exterior features and interface and doesnt worry about the internal functionality and work flow. It is one of the key concepts of OOP language. It was made to handle the complexity by hiding hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity.
Encapsulation: was also made to hide the complexity of code.
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of bundling data and methods that work on that data within one unit, e.g., a class in Java.
This concept is also often used to hide the internal representation, or state, of an object from the outside. This is called information hiding. The general idea of this mechanism is simple. If you have an attribute that is not visible from the outside of an object, and bundle it with methods that provide read or write access to it, then you can hide specific information and control access to the internal state of the object.
If you’re familiar with any object-oriented programming language, you probably know that these methods as getter and setter methods. As the names indicate, a getter method retrieves an attribute, and a setter method changes it. Depending on the methods that you implement, you can decide if an attribute can be read and changed, or if it’s read-only, or if it is not visible at all. As I will show you later, you can also use the setter method to implement additional validation rules to ensure that your object always has a valid state.
Inheritance: iThe irole ithat iinheritance iplays iin ithis ioptimization iis iin iallowing isoftware iengineers ito icreate iclass ihierarchies, iwhere iclasses iand iobjects iinherit iproperties iand ibehaviors ifrom itheir iparent i(or isuper) iclass. iA iclass ithat iinherits ifrom ia iparent i(or isuper) iclass iis icalled ia isubclass ior ichild iclass, iand iobjects ithat ireceive iproperties iand ibehaviors ifrom ia iparent ithrough iinheritance iare ireferred ito ias ichild iobjects.
Creating ia iunique iclass ifor ievery isingle ianimal iwould iquickly iget ivery irepetitious ibecause ithere iare isome iproperties iand ibehaviors ithat iapply ito ievery isingle ianimal, ifrom ia imouse ito ian ielephant. iShared ifunctions imight iinclude ifeed( i), ihydrate( i), icleanEnclosure( i). iInstead iof icreating ithese ishared iattributes iover iand iover ifor ievery ianimal, iwe icould iinstead icreate ia iparent iAnimal iclass! iThis iparent iclass iwould icontain ithe iproperties iand ibehaviors iuniversal ito iall ianimals iand isave ius ifrom ihaving ito icreate ithose ishared ifunctions iad iinfinitum.
In ithis iway, ian ielephant, ia imouse, iand ia ichimpanzee iwould iall ihave itheir iown ichild iclass iwhich iwould iinherit ifrom ithe iAnimal iparent iclass. iFurthermore, iNoah icould icontinue ito ibuild ion ithose iinherited iattributes ito ifurther icustomize ithese iclasses ias inecessary. iLastly, iinheritance iallows ius ito ilimit ithe ichances iof ihuman ierror ithat imight iarise iif imanually iinputting ithese ishared ifunctions.
There iare idifferent itypes iof iinheritance
1. Single iInheritance: iHere, ia inew iclass iis iderived ifrom ian iexisting iclass.
2. Multiple iinheritance: iHere, ia inew iclass iis iderived ifrom imultiple ibase iclasses
3. Multi ilevel iinheritance: iHere, ione iclass ican iinherit ifrom ia iderived iclass. iHence, ithe iderived iclass ibecomes ithe ibase iclass ifor ithe inewly icreated iclass
4. Hierarchical iinheritance: iHere, imultiple inew iclasses ican ibe icreated ifrom ia isingle iparent iclass/ ibase iclass
5. Hybrid iinheritance: iIt iis ia icombination ior i2 ior imore ithan i2 iinheritance
Polymorphism: iPolymorphism iis ithe icapability iof ia imethod ito ido idifferent ithings ibased ion ithe iobject ithat iit iis iacting iupon. iIn iother iwords, ipolymorphism iallows iyou idefine ione iinterface iand ihave imultiple iimplementations.
Real ilife iexample iof ipolymorphism: iA iperson iat ithe isame itime ican ihave idifferent icharacteristic. iLike ia iman iat ithe isame itime iis ia ifather, ia ihusband, ian iemployee. iSo ithe isame iperson iposses idifferent ibehaviour iin idifferent isituations. iThis iis icalled ipolymorphism.
Polymorphism iis iconsidered ias ione iof ithe iimportant ifeatures iof iObject iOriented iProgramming. iPolymorphism iallows ius ito iperform ia isingle iaction iin idifferent iways. iIn iother iwords, ipolymorphism iallows iyou ito idefine ione iinterface iand ihave imultiple iimplementations. iThe iword i“poly” imeans imany iand i“morphs” imeans iforms, iSo iit imeans imany iforms.
In iJava ipolymorphism iis imainly idivided iinto itwo itypes:
· Compile itime iPolymorphism
· Runtime iPolymorphism
Compile itime ipolymorphism: iIt iis ialso iknown ias istatic ipolymorphism. iThis itype iof ipolymorphism iis iachieved iby ifunction ioverloading ior ioperator ioverloading.
Runtime ipolymorphism:
iIt iis ialso
iknown
ias iDynamic
iMethod
iDispatch.
iIt iis ia iprocess
iin iwhich
ia ifunction
icall
ito
ithe ioverridden
imethod
iis iresolved
iat iRuntime.
iThis
itype
iof ipolymorphism
iis iachieved
iby iMethod
iOverriding
Roles iand iresponsibilities iof iinterface:
The ipurpose iof iinterfaces iis ito iallow ithe icomputer ito ienforce ithese iproperties iand ito iknow ithat ian iobject iof iTYPE iT i(whatever ithe iinterface iis i) imust ihave ifunctions icalled iX,Y,Z, ietc.
An iinterface iis ia iprogramming istructure/syntax ithat iallows ithe icomputer ito ienforce icertain iproperties ion ian iobject i(class). iFor iexample, isay iwe ihave ia icar iclass iand ia iscooter iclass iand ia itruck iclass. iEach iof ithese ithree iclasses ishould ihave ia istart_engine() iaction. iHow ithe i"engine iis istarted" ifor ieach ivehicle iis ileft ito ieach iparticular iclass, ibut ithe ifact ithat ithey imust ihave ia istart_engine iaction iis ithe idomain iof ithe iinterface.
Cohension: iCohesion iis
ithe iObject
iOriented iprinciple imost
iclosely iassociated iwith
imaking isure
ithat ia
iclass iis
idesigned iwith
ia isingle, iwell-focused ipurpose.
The imore ifocused ia
iclass iis,
ithe icohesiveness iof
ithat iclass
iis imore.
iThe iadvantages iof
ihigh icohesion iis
ithat isuch
iclasses iare
imuch ieasier
ito imaintain i(and
iless ifrequently ichanged) ithan
iclasses iwith
ilow icohesion. iAnother ibenefit iof
ihigh icohesion iis
ithat iclasses iwith
ia iwell-focused ipurpose itend
ito ibe
imore ireusable ithan
iother iclasses.
Example i: iSuppose iwe ihave ia iclass ithat imultiply itwo inumbers, ibut ithe isame iclass icreates ia ipop iup iwindow idisplaying ithe iresult. iThis iis ithe iexample iof ilow icohesive iclass ibecause ithe iwindow iand ithe imultiplication ioperation idon’t ihave imuch iin icommon.
Note: IF you can probide mw with code, then can relate these concepts with your assignment code.
Hope I answered the question.
If you have any doubts, or queries, feel free to ask
I'll respond to you as soon as I can.
Have a nice day