Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 5th, 2009, 08:07 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Lightbulb Class design in Java

I have 2 classes in Java with attributes as follows:

public class Student{
String name;
String address;
String course;
Professor advisor; //here i have used a user-defined type
}


public class Professor{
String name;
String address;
String course;
Student advisee; //here i have used a user-defined type
}

I want to make sure as to whether i am using "Composition" as an OOP technique here or not. If not then what is Composition in OOP, please explain clearly in detail with an example.
Thanks
__________________
MAXOOD!

Life is an endless journey towards perfection
  #2 (permalink)  
Old November 14th, 2011, 06:43 PM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by code_lover View Post
I have 2 classes in Java with attributes as follows:

public class Student{
String name;
String address;
String course;
Professor advisor; //here i have used a user-defined type
}


public class Professor{
String name;
String address;
String course;
Student advisee; //here i have used a user-defined type
}

I want to make sure as to whether i am using "Composition" as an OOP technique here or not. If not then what is Composition in OOP, please explain clearly in detail with an example.
Thanks
Yes you are using composition, in that you are composing your Student Class with a Professor attribute (and vice versa). Composition is a fancy way of saying has-a . You can read that a Student "has-a" Professor. The other common technique you might find is Inheritence. For which you can read "is-a". You could say a Student "is-a" Person (as is a Professor).

HTH
__________________
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about Class Design absolutezero C# 2008 aka C# 3.0 1 January 22nd, 2009 11:22 AM
class design jay.net General .NET 3 April 13th, 2007 07:59 AM
C# Class Design Handbook dchernin All Other Wrox Books 9 December 20th, 2004 09:02 AM
Java Design issue with UML and Design Patterns the_logical_way Apache Tomcat 0 May 31st, 2004 04:02 AM
Class Design Info... kaizer BOOK: Beginning Java 2 1 December 27th, 2003 06:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.