473,406 Members | 2,698 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,406 software developers and data experts.

help: composition, static factory method, immutability,...and beans

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 books? good/bad/mediocre/great/etc? are they
up to date, or out of date?

2.) please do check out my code at
http://www.geocities.com/cjavacjava/src/ comments welcome :)

3.) i'm very impressed with the idea(s) of using small immutable
classes for composition. it's massively simplified my efforts towards
a "sim" of a cat/dog ecosystem. is this a common technique? is it
"modern" and "trendy", or "old" and "tired"? or am i just scratching
the surface of how things are really done in java? (ignoring
smalltalk/c++/c#) are static factory's common?

4.) I presently have two classes, LifeForm and Location, and'll add a
"Driver" class. the idea is the driver class will hold the collection
(vector for now) of LifeForm objects, who'll wander around
independantly. maybe twice a second I'd like to get a LifeForm object
to make a call(?) to incrementX. I want each life form to move
totally independantly. good/bad idea? if ok, pls point me in the
direction to get started on that.

5.) if small, immutable classes truly give better performance and are
_easier_ to design/use/etc, then what's the big deal with beans?
seems a major contradiction.

thanks,

ja***@mail.com
Jul 17 '05 #1
2 3630
A bean is one thing, for one purpose; an immutable object is another, for
another purpose. Incidentally, there's nothing that says a bean can't be
immutable, but they often aren't. But just because a class (bean) has
getters and setters, that doesn't means it's mutable. For instance, a bean
that accepts only Strings in its getters is still immutable, because the
Strings themselves are immutable. And even if the object stored is mutable,
the bean can still be made mutable:

public setMyProperty(MyObject o)
{
_o = new MyObject(o);
}

I.e., we're storing a new copy of the object passed in, rather than a
reference to the one passed in.

In general, immutability is always good unless there's an overriding reason
not to use it. In other words, always prefer it, and make any given
situation "prove" that mutability is necessary.

Joshua Bloch's "Effective Java" talks about this stuff at length. I highly
recommend it. I'm only scratching the surface here, and he understands and
explains this stuff much better than I do.

As far as static factory methods, again, they make sense in certain
situations. I'm not sure if you're talking about the GoF static factory
method pattern, or just using static factory methods in place of
constructors.

An instance of the GoF pattern is iterator(). It meets three critera: 1)
It provides an instance of an object. 2) It provides a type, rather than a
specific implementation. (You don't know what specific implementation of
the Iterator interface is being returned). 3) It's used by several classes.

For Java patterns I recommend Steven Metsker's "Design Patterns Java
Workbook." It covers all of the GoF patterns in Java. And the author is
more than willing to respond to emails with questions.

You might be talking about simply using a static method to provide an
instance of a class, rather than constructors. For instance, you could
declare a class that has no public constructor, but has a getInstance()
method that returns an instance of the class. It might be a singleton, or
it might not; it doesn't matter to the client. This isn't a GoF pattern
usage, but it can be a very useful technique, avoiding the inherent problems
involved with constructors, but it has its own drawbacks. Again, Bloch
covers this topic in great detail and with wonderful clarity and relevance.

The most important thing I glean from your post is that you are thinking
critically about OO concepts in Java, and you obviously enjoy doing it, and
sharing your thoughts with other OO developers. That's always good.
Jul 17 '05 #2
"Dan Nuttle" <d_******@hotmail.com> wrote in message
news:a9****************@newsread2.news.atl.earthli nk.net...
A bean is one thing, for one purpose; an immutable object is another, for
another purpose. Incidentally, there's nothing that says a bean can't be
immutable, but they often aren't. But just because a class (bean) has
getters and setters, that doesn't means it's mutable. For instance, a bean that accepts only Strings in its getters is still immutable, because the
Strings themselves are immutable.


That's not accurate. If the bean has setters, it is mutable. Mutability
refers to the "changability" of the contents of an object. If a bean is
composed of three strings and has a setter for each (or even just one), can
the contents of the bean change? Yes, so it is mutable.

To the OP: You'd be better off posting to comp.lang.java.help in the future.
This group is not carried by all news servers, so many people don't see
posts here.
Jul 17 '05 #3

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

Similar topics

0
by: James Hong | last post by:
Help please, I try to sending an email from my html page using the java applet. but it give error on most of the PC only very few work, what is the error i make the java applet show as below ...
0
by: javac | last post by:
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: ...
1
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
17
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
5
by: Dinsdale | last post by:
I was discussing class architecture with one of the senior developers at my new job and him and I have a similar idea on how to work with data access and class libraries. That said, our...
11
by: Bryan Kyle | last post by:
Hi All, I'm fairly new to C# and Generics and I'm wondering if anyone has some suggestions for me. I'm trying to implement a simple DAO framework using generics to keep my code as clean as I...
9
by: Marc De Schrijver | last post by:
I'm designing an OO Model for a large application, and I have some question on how to model a particular situation; it's not directly related to C# but rather to general OO. The applicaiton will be...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.