Question

In: Computer Science

2.Discuss the two major benefits of using an interface and when would you use an abstract...

2.Discuss the two major benefits of using an interface and when would you use an abstract class in preference to an interface? Explain using examples

Solutions

Expert Solution

Answer:

Interface iis ian iindispensable imechanism iof iObject iOriented iprogramming. i iThe ireason iis ithat iinterface iallows iyou idescribe ithe icommunication icontract ibetween iobjects, iwhile iwith iclasses iyou idescribe inot ionly ithe icontract ibut ialso ia ibehavior. iSo iinterfaces icome iinto iplay ias isoon ias iyou ihave iobjects iwith ithe isame imethods iwhile ithey ihave inothing icommon iin itheir ibehavior iand ithis isituation iis imuch imost icommon irather ithan isituation iwhen iyou ihave ito iextend isome iclass.

One iof ithe ibenifits iof iusing iinterface iis ithat, ihere iimplementation idetail ican ibe ihidden ifrom ithe iuser, iless iconfusions iand ieasy iswapping ibetween iimplementations.

It iis ieasier ito imaintain ibackward icompatibility iand ikeeps ithe ilegacy iinterface iworking iwhile ibuilding inew iones.

iAbstract iclasses imay iprovide imembers ithat ihave ialready ibeen iimplemented. iTherefore, iyou ican iensure ia icertain iamount iof iidentical ifunctionality iwith ian iabstract iclass, ibut icannot iwith ian iinterface.

  • If iyou ianticipate icreating imultiple iversions iof iyour icomponent, icreate ian iabstract iclass. iAbstract iclasses iprovide ia isimple iand ieasy iway ito iversion iyour icomponents. iBy iupdating ithe ibase iclass, iall iinheriting iclasses iare iautomatically iupdated iwith ithe ichange. iInterfaces, ion ithe iother ihand, icannot ibe ichanged ionce icreated iin ithat iway. iIf ia inew iversion iof ian iinterface iis irequired, iyou imust icreate ia iwhole inew iinterface.
  • If ithe ifunctionality iyou iare icreating iwill ibe iuseful iacross ia iwide irange iof idisparate iobjects, iuse ian iinterface. iAbstract iclasses ishould ibe iused iprimarily ifor iobjects ithat iare iclosely irelated, iwhereas iinterfaces iare ibest isuited ifor iproviding icommon ifunctionality ito iunrelated iclasses.
  • If iyou iare idesigning ismall, iconcise ibits iof ifunctionality, iuse iinterfaces. iIf iyou iare idesigning ilarge ifunctional iunits, iuse ian iabstract iclass.
  • If iyou iwant ito iprovide icommon, iimplemented ifunctionality iamong iall iimplementations iof iyour icomponent, iuse ian iabstract iclass. iAbstract iclasses iallow iyou ito ipartially iimplement iyour iclass, iwhereas iinterfaces icontain ino iimplementation ifor iany imembers.

Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

Related Solutions

Give an example of when you would use reimbursable expenses and billable time. Discuss the benefits...
Give an example of when you would use reimbursable expenses and billable time. Discuss the benefits of Time and Billing. Are there any difficulties of using Time and Billing? Why or Why Not?
What is an example of when you would use a template? Name at least three benefits...
What is an example of when you would use a template? Name at least three benefits of using a workbook template.
1-Discuss the differences between size exclution chromatography and hydrodynamic chromatography ? 2- When would you use...
1-Discuss the differences between size exclution chromatography and hydrodynamic chromatography ? 2- When would you use each of these?
When would you choose to use containers in Windows and when would you choose to use...
When would you choose to use containers in Windows and when would you choose to use containers in Linux? How are they different? How are they similar?
Discuss the first 3 steps you would take when using an AED.
Discuss the first 3 steps you would take when using an AED.
Discuss the purpose of a switch below:    1. Benefits of using a switch    2....
Discuss the purpose of a switch below:    1. Benefits of using a switch    2. Types of switches    3. How is a switch used in a network infrastructure
Discuss TWO benefits the UK probably experienced as a result using their own currency.
Discuss TWO benefits the UK probably experienced as a result using their own currency.
Discuss the limitations of BMI. Discuss when it would be most appropriate to use BMI and...
Discuss the limitations of BMI. Discuss when it would be most appropriate to use BMI and describe instances when another more formal technique should be utilized and why?
Discuss the differences between Excel and Access, when you would use one over the other and...
Discuss the differences between Excel and Access, when you would use one over the other and how/when you can use them together to achieve a goal.
8–2 Discuss some of the major benefits to be gained from budgeting. 8–3 What is meant...
8–2 Discuss some of the major benefits to be gained from budgeting. 8–3 What is meant by the term responsibility accounting? 8–4 What is a master budget? Briefly describe its contents. 8–5 Why is the sales forecast the starting point in budgeting? 8–6 “As a practical matter, planning and control mean exactly the same thing.” Do you agree? Explain. 8–8 What is a self-imposed budget? What are the major advantages of self-imposed budgets? What caution must be exercised in their...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT