Skip to content

Instantly share code, notes, and snippets.

@malalanayake
Last active April 11, 2016 18:10
Show Gist options
  • Save malalanayake/a3cc12ce51344d59d6923eda2668b753 to your computer and use it in GitHub Desktop.
Save malalanayake/a3cc12ce51344d59d6923eda2668b753 to your computer and use it in GitHub Desktop.
Single Responsibility Principal - Bad sample code
package sample.design.single.responsibility.bad;
/**
*
* Distibution under GNU GENERAL PUBLIC LICENSE Version 2, June 1991
*
* @author dmalalan
* @created Apr 11, 2016 11:20:19 AM
*
* @blog https://malalanayake.wordpress.com/
*/
public class Book {
private int bookId;
private String name;
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
* 1. Get DB connection and 2. Create transaction 3. Save the book 4. Commit
* transaction
*/
public void saveBook() {
System.out.println("[SAVE:BOOK " + this.bookId + "]");
}
/**
* 1. Get DB connection and 2. Create transaction 3. Update the book 4.
* Commit transaction
*/
public void updateBook() {
System.out.println("[UPDATE:BOOK " + this.bookId + "]");
}
/**
* 1. Get DB connection and 2. read the book
*
*/
public void readBook() {
System.out.println("[READ:BOOK " + this.bookId + "]");
}
/**
* 1. Get DB connection and 2. Create transaction 3. Delete the book 4.
* Commit transaction
*/
public void deleteBook() {
System.out.println("[DELETE:BOOK " + this.bookId + "]");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment