#Implementation of Labwork

1 messages · Page 1 of 1 (latest)

left chasm
#

Hi all, wrote a Java program to decorate text, now I could be misunderstanding the lab sheet so i came here to see if I did what i was supposed to thanks o/

package LinkDecoratorWithAdapter;

public class Client {
    public static void main(String[] args) {
        MessageDecorator messageDecorator = new MessageDecorator("design-patterns.com");
        messageDecorator.output();
    }
}
public class MessageDecorator {
    String inputMessage;
    public MessageDecorator(String message) {
        inputMessage = message;
    }
    public void output(){
        System.out.println("Text object show()");
        System.out.println(inputMessage + "\n");

        System.out.println("Http decorated text show()");
        System.out.println(getHttpDecorated() + "\n");

        System.out.println("Ftp decorated text show()");
        System.out.println(getFtpDecorated() + "\n");

        System.out.println("Https decorated text show()");
        System.out.println(getHttpsDecorated());
    }
    public String getHttpDecorated(){
        String message = inputMessage;
        message = "http://" + message;

        return message;
    }
    public String getFtpDecorated(){
        String message = inputMessage;
        message = "ftp." + message;

        return message;
    }
    public String getHttpsDecorated(){
        String message = inputMessage;
        message = "https://" + message;

        return message;
    }
}
marble ferryBOT
# left chasm Hi all, wrote a Java program to decorate text, now I could be misunderstanding t...

Detected code, here are some useful tools:

Formatted code
package LinkDecoratorWithAdapter;

public class Client {
  public static void main(String[] args) {
    MessageDecorator messageDecorator = new MessageDecorator("design-patterns.com");
    messageDecorator.output();
  }
}
public class MessageDecorator {
  String inputMessage;
  public MessageDecorator(String message) {
    inputMessage = message;
  }
  public void output() {
    System.out.println("Text object show()");
    System.out.println(inputMessage + "\n");
    System.out.println("Http decorated text show()");
    System.out.println(getHttpDecorated() + "\n");
    System.out.println("Ftp decorated text show()");
    System.out.println(getFtpDecorated() + "\n");
    System.out.println("Https decorated text show()");
    System.out.println(getHttpsDecorated());
  }
  public String getHttpDecorated() {
    String message = inputMessage;
    message = "http://" + message;
    return message;
  }
  public String getFtpDecorated() {
    String message = inputMessage;
    message = "ftp." + message;
    return message;
  }
  public String getHttpsDecorated() {
    String message = inputMessage;
    message = "https://" + message;
    return message;
  }
}
#

<@&987246883653156906> please have a look, thanks.

left chasm
#

Text object show()
design-patterns.com

Http decorated text show()
http://design-patterns.com

Ftp decorated text show()
ftp.design-patterns.com

Https decorated text show()
marble ferryBOT
left chasm
#

output for those who need it

#

last one didn't go through

normal girder
#

You need to make an interface

#

Then Make 1 abstract class that implement it

#

then each children need to be able to be constructed by giving it another decorator

#

that way you can stack decoration

#

Like a russian doll

left chasm
#

huh, just found out there's sample code that basically does all that

#

does exactly what i need it to do

#

which is odd

left chasm
#

okay so i got it wokring

#

except it does the exact same thing as the example code and i have no idea what my lecturer expected of me?

#
package LinkDecoratorWithAdapter;

public interface Content {
    void show();
}

vs

package NonVisualDecorator;

public abstract class Content{
    public void show(){}
}

marble ferryBOT
left chasm
#

and that's it?

normal girder
#

Can you put one into another?

left chasm
#

oh

#

i guess you could but it would be odd

#

guess it's more to do with the theory questions

#

i suppose?

normal girder
#

Why would it be odd?

#

It is the whole point of the pattern

left chasm
#

i can yeah

#

but i thought you meant put the abstract content into the interface content

#

or is that what you implied

normal girder
#

No

#

It is more, put a blue decorator around the green decorator

#

Then put a red decorator around this

#

Or imagine 3d shape

#

You put a pyramid, in a box, in a sphere

left chasm
#

yeah the russian doll concept

#

that's the structure

#

so decorator implements Content, Ftp, Http/s extends decorator

normal girder
#

Show the generated graph

left chasm
#

the generated graph?

left chasm
#

ahhhh

#

that's pretty cool actually

#

wow

normal girder
#

Can you copy the requirements?

left chasm
#

so if this tool exists do i ever have to do umls again?

normal girder
#

here

normal girder
left chasm
#
g) Using the code provided in resources and the lecture notes this week, write a
Java code implementation where output from the main() method in the Client
class should look as follows:

Text object show()
design-patterns.com
Http decorated text show()
http://www.design-patterns.com
Ftp decorated text show()
ftp.design-patterns.com
Https decorated text show()
https://www.design-patterns.com

h ) On completion of your implementation of the code in part g) above.
draw a UML diagram to reflect your updated decorator code base,

marble ferryBOT
normal girder
#

this is just to confirm

left chasm
#

well usually i just code it first then

#

you know do the uml?

last hollow
#

Use the tools