473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

immutability & composition

http://java.sun.com/docs/books/performance/ listing 7-11:
---------------
If the following code is written in a package seperate from the
Location class, it will now cause compile-time errors:

Location loc = body.getLocation();
loc.x = 5; //field x is not accessible;
loc.setX(5); //method setX not found in class Location

Be aware, however, that it is possible to cast the returned Location
object to a MutableLocation. The following code will work and is
quite dangerous.

Location loc = body.getLocation();
MutableLocation mLoc = (Mutable)loc;
mLoc.setX(5);

Listing A-1:
------------
public class CatTest{
static Vector catList = new Vector();
static void makeCat() {
Object cat = new Cat();
catList.addElement(cat);
}

public static void main(string[] arg) {
makeCat();
// do more stuff
}
}

I'm using this "pattern," but solely with immutable classes at
http://www.geocities.com/cjavacjava/...LifeForms.java

unfortunately, when I try to do things, like change x coordinate in a
location object, I'm not getting the result I want. I'm looking for
constructive criticism, please.

ja***@mail.com
Jul 17 '05 #1
0 1504

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: javac | last post by:
for better or worse, my free time is consumed by two Java series books from Sun: Java Platform Performance, 2000, by Wilson and Kesselman Effective Java, 2001, by Bloch 1.) opinions on these...
4
by: fog | last post by:
Given: class A; and B "has-a" A. The composition relationship between A and B can be implemented in three ways: =================== # 1. class B {
7
by: preetam | last post by:
Hi, This question is more towards design than towards c++ details. By looking at books on design patterns and various google threads on the same topic, I see that composition is favoured to...
9
by: Code4u | last post by:
My colleagues and I have been discussing techniques for implementing interfaces in C++. We're looking for a mechanism similar to COM's QueryInterface, in which a certain types of objects can be...
4
by: cmrchs | last post by:
Hi, how do I implement aggregation and how composition in C# ? When I say : an Airplane has a Pilot then I use aggregation but when I say : an Airplane has a Cockpit then I use composition. How...
4
by: Frederik Vanderhaegen | last post by:
Hi, Can anyone explain me the difference between aggregation and composition? I know that they both are "whole-part" relationships and that composition parts are destroyed when the composition...
3
by: Terry Hancock | last post by:
Is there an *easy* way to make an object immutable in python? Or perhaps I should say "one obvious way to do it"? Oughtn't there to be one? I've found a thread on how to do this, which...
2
by: Gary Wessle | last post by:
Hi what is the difference "in code writing" between aggregation and composition? is the following correct? aggregation (life time of both objects are independent). class A{ /* ... */ };...
3
by: jyck91 | last post by:
I want to get some ideas to organise a composition analyzer?? eg. frequencies of letters Thx for your suggestion
5
by: jyck91 | last post by:
Can anyone give me some ideas to organise a composition analyzer in C? It analyses an english composition. What functions should it include? eg. frequency of letter/ words thanks for help
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.