This is the Skeleton of my current class
class JokeTemplates
{
public function CheckTemplateCategory()
{
}
public function SubmitUserTemplates()
{
}
Public function ShowUserUploadedTemplates()
{
}
public function ShowUSerFOrwardedTemplates()
{
}
public function ShowAllTemplates()
{
}
}
In future i may have to design many such classes like LoveTemplates,FriendshipTemplates,BirthdayTemplates..etc
In which some of the functions like SubmitUserTemplates, ShowUserUploadedTemplates, ShowUSerFOrwardedTemplates may remain same While functionality of some of function Like ShowAllTemplates,CheckTemplateCategory etc. may change.
IF i create all the functions(copy-paste) in my all classes ,it will lead to huge code redundancy.
How should i design my code to reduce redundancy.
That’s what inherianceDocs is for:
You define the
Templatestype per it’s interfaceDocs:You create a base templates (I call it
TemplatesBase) that is of typeTemplatesper the implementation of the Interface. You can start to write actual code here into the function:or alternatively with abstractionDocs:
Finally you can extend from that class and only add the function you need: