• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

abstract classes and interfaces

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realise this subject has been covered in an earlier thread, but I would like to just ask the same question coming from a differant angle.Abstract classes can have empty(abstract methods),or concrete methods .interfaces are abstract but cannot contain any code apart from empty methods(abstact) and whereas with subclasses being only able to access one abstract class ,subclassess can implement many interfaces at differant levels .I would like to add what I think is happening with regards to why these differant classes are used and then someone may point me in the correct direction.

Related subclasses use abstract classes to link objects together of a related type .rather than having classes seperate at birth they are connected in a relationship where the parent has the same genes as the children. All the abstract methods in the parent form a signature which the child can impliment and override to form it`s own implimentations of the methods.So in reality what is happening is a common ground between all subclasses is being established.

Interfaces enable multiple sharing by subclasses but allow only method definitions and no implementation of any sort.
 
Daniel Hyslop
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just to add to my thread above . Using abstract and interface seems pretty straight forward in an explanation of implimentation uses but in what circumstances can you measure where such methods should be used
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is a good oportunity to check my aproach

in the app i'm developing (home stuff) i have: the boss, the private care (prv) client and the public care client (pub). In order to have everything properly established, an agreement (contract) is made with date, which client, service type, cost, etc.

I came up with inheritance, since both contracts between boss and prv or boss and pub have so much in common. So i created a superclass AbrstractContract from which PrivateContract and PublicContract inherit;

and abstract precisely because i've a method cost() that should be implemented by every subclass in its own way. (i know i could as well have defined the method in superclass and then having each children overriden it)

As to interfaces, the idea is having related or unrelated classes having a common set of behaviour.

i'd refer to my use of it in here.

hope i was clear enough
 
We can walk to school together. And we can both read this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic