"chris sennitt" <> wrote in message
news:y2G2c.575$...
>
> "Ryan Stewart" <> wrote in message
> news:UdCdnYfk3aAEtNbdRVn-...
> > "chris sennitt" <> wrote in message
> > news:kbF2c.2$...
> > > > If you want to be able to do this, could you not class cast the
object
> > > back to bClass?
> > > > ((bClass)b.aa()).bb()
> > > > That's the only way I think you can do what you want to do in one
> line.
> > > >
> > > lol - well the idea was to make the code concise and simple to read 
> > >
> > A cast doesn't make code difficult to read, but chaining method calls
> does.
>
> i agree, chaining can make the code un readable, however in this case it
> works well.
>
> oHtmlText.bold().italic().font("blahblah").size(12 ).colour("blahblah");
>
> seems reasonably easy to read
>
> or casting as a work around .........
>
> ( (htmlText)( (htmlText) ( (htmlText) ( (htmlText)
>
oHtmlText.bold() ).italic() ).font("blahblah") ).size(12) ).colour("blahblah
> ");
>
> seems pretty confusing to me and , yes i may have missed some brackets
> somewhere but as u can see, casting is not an option here
>
Yeah, that's ugly. Is that what you're trying to do with Java? The
..bold().italic().... thing? Why don't you make a Style object that lets you
call those methods to set its state, then associate your oHtmlText and
whatever other objects with a Style object? Then the methods in your Style
class can each return a Style object and you get the effect you're looking
for. Something like:
public class HtmlText {
private Style style;
private String text;
public void setStyle(Style style) {
this.style = style;
}
public void setText(String text) {
this.text = text;
}
public static void main(String[] args) {
Style myStyle = new Style().bold().italic();
HtmlText ht = new HtmlText();
ht.setStyle(myStyle);
}
}
class Style {
private boolean bold = false;
private boolean italic = true;
// Other states
private Style bold() {
this.bold = true;
return this;
}
private Style italic() {
this.italic = true;
return this;
}
}
This code may have typos. I just typed it in here, don't have time to check
it right now. You should be able to get the general idea though.