Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.