• Post Reply Bookmark Topic Watch Topic
  • New Topic

An object that supports different properties  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this abstract class

Subclasses will return an array of Bar. Bar needs to be a subclass of Node (that's all).

what I want to do is such that Bar may contain different sets of values & that is determined by the subclasses themselves. What I mean by the last sentence is this:

Assume Subclass1's Bar returns 3 properties: age, name, address.
Then Subclass2's Bar can return 2 properties: birthdate, gender.

I'm thinking that the subclasses of Bar should contain internally a Properties object. I will not have specific getters like getAge(), getGender() because these are completely arbitrary. Am I doing the right thing? Am I making sense?

Thanks

Pho
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the method name "enumerate()" .. Are you familiair with enums? I guess this is exactly what you need.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went ahead and wrapped a Properties instance. It works.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!