1b: add AuthoredItem as superclass for Article and Image

This commit is contained in:
Daniel Langbein 2024-11-24 18:56:13 +01:00
parent 261f9bb800
commit db12a40520
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
3 changed files with 40 additions and 64 deletions

View File

@ -1,10 +1,6 @@
package model; package model;
public class Article extends Item { public class Article extends AuthoredItem {
private String title;
private String author;
private String content;
// Fill in dummy content // Fill in dummy content
{ {
content = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, " content = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
@ -34,30 +30,4 @@ public class Article extends Item {
+ getContent() + getContent()
+ "\n\n"; + "\n\n";
} }
//=================================
/**
* Get the title of the article.
* @return title
*/
public String getTitle() {
return title;
}
/**
* Get the author of the article.
* @return author
*/
public String getAuthor() {
return author;
}
/**
* Get the content of the article.
* @return
*/
public String getContent() {
return content;
}
} }

View File

@ -0,0 +1,33 @@
package model;
public abstract class AuthoredItem extends Item{
protected String title;
protected String author;
protected String content;
/**
* Get the title of the AuthoredItem.
*
* @return title
*/
public String getTitle() {
return title;
}
/**
* Get the author of the AuthoredItem.
*
* @return author
*/
public String getAuthor() {
return author;
}
/**
* Get the content of the AuthoredItem.
* @return content
*/
public String getContent() {
return content;
}
}

View File

@ -1,11 +1,14 @@
package model; package model;
public class Image extends Item { public class Image extends AuthoredItem {
private String title;
private String author;
private int width; private int width;
private int height; private int height;
// Fill in dummy content
{
content = " /\\_/\\ \n( o.o )\n > ^ < ";
}
/** /**
* Creates an image with the given title and author and a resolution * Creates an image with the given title and author and a resolution
* defined by width and height. * defined by width and height.
@ -38,24 +41,6 @@ public class Image extends Item {
//================================= //=================================
/**
* Get the title of the image.
*
* @return title
*/
public String getTitle() {
return title;
}
/**
* Get the author of the image.
*
* @return author
*/
public String getAuthor() {
return author;
}
/** /**
* Get the width of the image. * Get the width of the image.
* *
@ -73,16 +58,4 @@ public class Image extends Item {
public int getHeight() { public int getHeight() {
return height; return height;
} }
/**
* Renders the image as String and return the rendered image.
*
* @return String representing the rendered image
*/
public String getContent() {
/*
* Dummy implementation
*/
return " /\\_/\\ \n( o.o )\n > ^ < ";
}
} }