Cor,
| In my opinion does Boss derives from Employees when he has himself
Employees
| or any other reasons that does distinct him from an employee.
I am not disputing that. As I stated, Herfried & Mitchell gave the
inheritance with cloning solution.
A well know OO alternative to Inheritance is the Role Pattern. The Role
Pattern is useful when an object (Employee) needs to change its type (Boss).
Especially when copying & cloning may not be desirable! The "best"
discussion that I know of on the Role Pattern is in Peter Coad's, Mark
Mayfield's, and Jon Kern's book "Java Design - Building Better Apps &
Applets". They discuss this problem & how to implement it with Inheritance &
how to implement it with the Role pattern & why you would choose one over
the other. You can also use google to search for "Role Pattern" (include the
quotes) to find a number of useful links. I would suggest these:
http://www.cs.wustl.edu/~doc/RandD/P...ole-object.pdf http://wiki.cs.uiuc.edu/AnalysisPatterns/Party
I'm sure there are others, the second link uses the term "actor-role
pattern".
Basically inheritance is useful when you need "is a special kind of" (a Boss
is a special kind of Employee) while the Role Pattern is when you need "is a
role played by" (Boss is a role played by an Employee). So I hope you see
both are applicable here.
I hope you agree one of the major problems with inheriting & cloning an
Employee is when you have many references to that Employee? If you clone it
you will need to change all the references, how do you know what all those
references are? If you implement the Role Pattern you just need to change
the Role property.
Another major problem with inheriting & cloning an Employee is what happens
when the Employee can hold multiple roles? What happens when the employee is
both a Boss & Administrative Assistant? Remember that .net does not allow
multiple inheritance. With the Role pattern Employee could have a
RoleCollection and/or PrimaryRole & SecondaryRole properties. Allowing that
Employee to hold multiple Roles.
Consider the example from the Java Design book:
Class Person - represents a person
Class Agent : Inherits Person - a person who sells airline tickets
Class Passenger : Inherits Person - a person who rides on the plane
Now how do you represent a person riding on a plan who sells Airline
tickets?
Class AgentPassenger : Inherits Agent : Inherits Passenger
Oops: You can only inherit from a single base class.
Hence the use of Roles
Class Person - Represents a person
Class PersonRole - represents the roles that a person can have
Class AgentRole - Inherits PersonRole
Class PassengerRole - Inherits PersonRole
If Person can have 0 to many PersonRole objects, that Person can be both an
Agent & a Passenger.
| As I understand your solution well than looks it for me the same as giving
| feathers to a mammal because more animals have that.
Huh?
Please take the time to fully understand the Role Pattern before commenting
further! Thank you!
Hope this helps
Jay
"Cor Ligthert" <no************@planet.nl> wrote in message
news:O5****************@TK2MSFTNGP14.phx.gbl...
| Jay,
|
| In my opinion does Boss derives from Employees when he has himself
Employees
| or any other reasons that does distinct him from an employee.
|
| As I understand your solution well than looks it for me the same as giving
| feathers to a mammal because more animals have that.
|
| I think that is a very essential point in this thread and for me that what
| the OP not want to do.
|
| What in my opinion means that he want to use a Boss object as an Employee.
|
| In code something like this very short and bad written.
|
| \\\
| Public Class Test
| Public Shared Sub Main()
| Dim a As New Employee
| a.name = "Jan"
| Dim b As Employee
| b = New Boss
| b.name = "Piet"
| DirectCast(b, Boss).Add(a.name)
| End Sub
| End Class
| Public Class Employee
| Public name As String
| End Class
| Public Class Boss : Inherits Employee
| Public employees As New ArrayList
| Public Sub Add(ByVal emp As String)
| employees.Add(emp)
| End Sub
| End Class
| ///
|
| Because I saw already so many messages, did I not wanted to add this,
| because this is something I am sure of that it does not add much to your
| knowledge and thought maybe can you tell that.
|
| However when you don't agree will I without any problem add this to the
main
| thread.
|
| :-)
|
| Cor
|
|