"this" statement?  
Author Message
JS





PostPosted: 2005-1-18 3:22:00 Top

java-programmer, "this" statement? The "this" statement that is used in the method "exitRoom" and "explore" is
that synonymous with an "Explorer" object?


public class Explorer implements PlayerBehavior {

private String my_name;
private String my_secret_word;
private RoomBehavior where_I_am_now;

public Explorer(String name, String word){

my_name = name;
my_secret_word = word;
where_I_am_now = null;

}

public String speak(){

return my_secret_word; }


public void exitRoom(){

if ( where_I_am_now != null )
{ where_I_am_now.exit(this);
where_I_am_now = null;
}
}

public boolean explore(RoomBehavior r){

if ( where_I_am_now != null )
{ exitRoom(); }

boolean went_inside = r.enter(this);
if ( went_inside )
{ where_I_am_now = r; }
return went_inside;
}

public RoomBehavior locationOf(){

return where_I_am_now; }
}


 
Thanasis (sch)





PostPosted: 2005-1-18 6:04:00 Top

java-programmer >> "this" statement? exactly. this means the current object of Explorer class

"JS" <email***@***.com> wrote in message news:csh32s$n2i$email***@***.com...
> The "this" statement that is used in the method "exitRoom" and "explore"
> is
> that synonymous with an "Explorer" object?
>
>
> public class Explorer implements PlayerBehavior {
>
> private String my_name;
> private String my_secret_word;
> private RoomBehavior where_I_am_now;
>
> public Explorer(String name, String word){
>
> my_name = name;
> my_secret_word = word;
> where_I_am_now = null;
>
> }
>
> public String speak(){
>
> return my_secret_word; }
>
>
> public void exitRoom(){
>
> if ( where_I_am_now != null )
> { where_I_am_now.exit(this);
> where_I_am_now = null;
> }
> }
>
> public boolean explore(RoomBehavior r){
>
> if ( where_I_am_now != null )
> { exitRoom(); }
>
> boolean went_inside = r.enter(this);
> if ( went_inside )
> { where_I_am_now = r; }
> return went_inside;
> }
>
> public RoomBehavior locationOf(){
>
> return where_I_am_now; }
> }
>
>


 
JS





PostPosted: 2005-1-18 17:49:00 Top

java-programmer >> "this" statement? Is it possible to write the "explorer" method without using "this" and how
would it look?




"Thanasis (sch)" <email***@***.com> skrev i en meddelelse
news:41ec360d$email***@***.com...
> exactly. this means the current object of Explorer class
>
> "JS" <email***@***.com> wrote in message
news:csh32s$n2i$email***@***.com...
> > The "this" statement that is used in the method "exitRoom" and "explore"
> > is
> > that synonymous with an "Explorer" object?
> >
> >
> > public class Explorer implements PlayerBehavior {
> >
> > private String my_name;
> > private String my_secret_word;
> > private RoomBehavior where_I_am_now;
> >
> > public Explorer(String name, String word){
> >
> > my_name = name;
> > my_secret_word = word;
> > where_I_am_now = null;
> >
> > }
> >
> > public String speak(){
> >
> > return my_secret_word; }
> >
> >
> > public void exitRoom(){
> >
> > if ( where_I_am_now != null )
> > { where_I_am_now.exit(this);
> > where_I_am_now = null;
> > }
> > }
> >
> > public boolean explore(RoomBehavior r){
> >
> > if ( where_I_am_now != null )
> > { exitRoom(); }
> >
> > boolean went_inside = r.enter(this);
> > if ( went_inside )
> > { where_I_am_now = r; }
> > return went_inside;
> > }
> >
> > public RoomBehavior locationOf(){
> >
> > return where_I_am_now; }
> > }
> >
> >
>
>


 
 
Thanasis (sch)





PostPosted: 2005-1-19 6:59:00 Top

java-programmer >> "this" statement? what is the code for RoomBehavior?

"JS" <email***@***.com> wrote in message news:csilsl$654$email***@***.com...
> Is it possible to write the "explorer" method without using "this" and how
> would it look?
>
>
>
>
> "Thanasis (sch)" <email***@***.com> skrev i en meddelelse
> news:41ec360d$email***@***.com...
>> exactly. this means the current object of Explorer class
>>
>> "JS" <email***@***.com> wrote in message
> news:csh32s$n2i$email***@***.com...
>> > The "this" statement that is used in the method "exitRoom" and
>> > "explore"
>> > is
>> > that synonymous with an "Explorer" object?
>> >
>> >
>> > public class Explorer implements PlayerBehavior {
>> >
>> > private String my_name;
>> > private String my_secret_word;
>> > private RoomBehavior where_I_am_now;
>> >
>> > public Explorer(String name, String word){
>> >
>> > my_name = name;
>> > my_secret_word = word;
>> > where_I_am_now = null;
>> >
>> > }
>> >
>> > public String speak(){
>> >
>> > return my_secret_word; }
>> >
>> >
>> > public void exitRoom(){
>> >
>> > if ( where_I_am_now != null )
>> > { where_I_am_now.exit(this);
>> > where_I_am_now = null;
>> > }
>> > }
>> >
>> > public boolean explore(RoomBehavior r){
>> >
>> > if ( where_I_am_now != null )
>> > { exitRoom(); }
>> >
>> > boolean went_inside = r.enter(this);
>> > if ( went_inside )
>> > { where_I_am_now = r; }
>> > return went_inside;
>> > }
>> >
>> > public RoomBehavior locationOf(){
>> >
>> > return where_I_am_now; }
>> > }
>> >
>> >
>>
>>
>
>