I'm studying for my object-otiented programming final (C++) and going over some of our past tests. One question asks to describe an as-a relationship. I understand the is-a and has-a relationships, but can't seem to find any information on as-a relationships. Can someone give me a brief explanation of this?
-
(has-a) minus an h? (is-a) swap the 'i' for an 'a'. I am going for the fact that it is a typo. Note that sometimes has-a relationship is described inversely as a part-of relationship. – Derek W Dec 11 '14 at 03:24
-
I could make up a useful pattern called 'as-a' (as an example, 'as-a' iterable is a class that supports ranged iteration: this is neither 'is-a' nor 'has-a', as I can add this support without changing what the object is.) (or, maybe the existance of adapters implying 'as-a'). But, I haven't heard of it being used. – Yakk - Adam Nevraumont Dec 11 '14 at 03:27
-
I finally found it in my notes, for some reason I didn't list it with the other pages covering the review for that exam. Here's how my professor described it "end of hierarchy, stops it from existing further". – Beth Tanner Dec 11 '14 at 03:39
4 Answers
There is no such thing. Most likely the question contains a typographical error. Consult its author, who may also have invented the term for your course, in which case no one here may know precisely what it is intended to mean.

- 239,568
- 38
- 324
- 436
-
Finally found it in my notes, here's what my professor described it as "the end of the hierarchy, stops it from existing further". – Beth Tanner Dec 11 '14 at 03:38
-
Be ware though...An "Inheritance hierarchy" means "Is A" not "Has A". – NoChance Dec 11 '14 at 03:50
See this wikipedia article about the has a relationship which describes various types of relationships http://en.wikipedia.org/wiki/Has-a
The only two that I have ever heard of are the is a (subtyping or inheritance) and the has a (composition or used as a member of a class).
One possibility may be the idea of using composition, the has a relationship, and then supporting an interface that is a subset of the member or a component of which the class or object is composed. This might also be done through private inheritance and then duplicating selected portions of the base class interface. See this stackoverflow Private inheritance VS composition : when to use which?
And see this stackoverflow about the HAS-A and IS-A relationship HAS-A, IS-A terminology in object oriented language which also mentions aggregation as well as composition and inheritance.
And see this wikipedia article on composition versus inheritance http://en.wikipedia.org/wiki/Composition_over_inheritance

- 1
- 1

- 16,643
- 4
- 81
- 106
Most likely "as a" is a typo, but regarded as a descriptive term it can refer to the relationship you have in e.g. to_string
, which you can rename as as_string
.
However, at the time when I still didn't mind reading and writing too much, not so verbosity-challenged as I'm now, I used to call that operation string_from
. De-emphasizing the idea of a fixed relationship between the two sets of values. And emphasizing the one-way nature of the conversion.

- 142,714
- 15
- 209
- 331
The "Has-A" relationship describes containment of a class within another and or composition of a class of 1 or more other classes. It is different from "Is-A". For more details, please refer to (among others):
Object-oriented Programming: Using C++ for Engineering and Technology.
Effective C++ Digital Collection: 140 Ways to Improve Your Programming.

- 5,632
- 4
- 31
- 45