samedi 15 septembre 2018

Designing 2 dimensional and 3 dimensional class under same shape class

I have a scenario in which I have shape, 2 dimensional shape , 3 dimensional shape, circle , square, cube and cylinder. for 2 dimensional I have to provide area method and for 3 dimensional I have to provide volume method and area method. Conditions are given below. in below image, dotted line means "somehow related".

This is what I have to implement

  • I can use interface, abstract class and class.
  • Two dimensional classes should have area method but not volume method.
  • Three dimensional classes should have volume and area of any 2d surface inside that shape for e.g. cube can have area of any of its side.

How can I design this? where should methods reside? how can I restrict volume method to 3 dimensional classes only?

Aucun commentaire:

Enregistrer un commentaire