Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Query on use of inheritance using restriction  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the real use of restriction?

Why cant we just declare a new type? I dont understand...

Could someone please help
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Abhishek Dharwadkar:
Why cant we just declare a new type?



Of course you can.

In fact Nicolai Josuttis states in SOA in Practice: The Art of Distributed System Design (p44):

Based on my own experience (and others), I recommend that you have a basic set of fundamental types that you can compose to other types (structures, records) and sequences (arrays). Be careful with enumerations (an anachronism from the time when each byte did count - use strings instead), inheritance and polymorphism (even when XML supports it).



However the concept of restriction is supposed to help eliminate duplication from the schema.

Also restriction isn't inheritance in the polymorphic sense - i.e. you can't always use the derived type in place of the parent-type because the derived type is more constrained than the parent type. Restriction is used to create new types by placing additional constraints on an existing type - the existing type is often a base XML type. For example:

a lower case alpha string with at least 6 but no more than 8 letters


an integer with an allowable range of 0-99


constrained temperature types
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peer
 
Abhishek Dharwadkar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peer for such a good explanation
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!