├── Document.php ├── Parser.java └── README.md /Document.php: -------------------------------------------------------------------------------- 1 | 5); 10 | $this->user = $user; 11 | $this->name = $name; 12 | } 13 | 14 | public function getTitle() { 15 | $db = Database::getInstance(); 16 | $row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1'); 17 | return $row[3]; // third column in a row 18 | } 19 | 20 | public function getContent() { 21 | $db = Database::getInstance(); 22 | $row = $db->query('SELECT * FROM document WHERE name = "' . $this->name . '" LIMIT 1'); 23 | return $row[6]; // sixth column in a row 24 | } 25 | 26 | public static function getAllDocuments() { 27 | // to be implemented later 28 | } 29 | 30 | } 31 | 32 | class User { 33 | 34 | public function makeNewDocument($name) { 35 | $doc = new Document(); 36 | $doc->init($name, $this); 37 | return $doc; 38 | } 39 | 40 | public function getMyDocuments() { 41 | $list = array(); 42 | foreach (Document::getAllDocuments() as $doc) { 43 | if ($doc->user == $this) 44 | $list[] = $doc; 45 | } 46 | return $list; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Parser.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileInputStream; 3 | import java.io.FileOutputStream; 4 | import java.io.IOException; 5 | /** 6 | * This class is thread safe. 7 | */ 8 | public class Parser { 9 | private File file; 10 | public synchronized void setFile(File f) { 11 | file = f; 12 | } 13 | public synchronized File getFile() { 14 | return file; 15 | } 16 | public String getContent() throws IOException { 17 | FileInputStream i = new FileInputStream(file); 18 | String output = ""; 19 | int data; 20 | while ((data = i.read()) > 0) { 21 | output += (char) data; 22 | } 23 | return output; 24 | } 25 | public String getContentWithoutUnicode() throws IOException { 26 | FileInputStream i = new FileInputStream(file); 27 | String output = ""; 28 | int data; 29 | while ((data = i.read()) > 0) { 30 | if (data < 0x80) { 31 | output += (char) data; 32 | } 33 | } 34 | return output; 35 | } 36 | public void saveContent(String content) { 37 | FileOutputStream o = new FileOutputStream(file); 38 | try { 39 | for (int i = 0; i < content.length(); i += 1) { 40 | o.write(content.charAt(i)); 41 | } 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [logo](https://elegantobjects.org) 2 | 3 | Imagine you're assigned as a developer to this project and you 4 | have to make the first step in the refactoring of one of these classes 5 | (choose one, by the language you're most comfortable with). 6 | There are many issues in these classes, even though they compile and work. 7 | 8 | Please, submit a pull request with the changes you would recommend to 9 | do here. Try to spend **15 minutes** maximum for the entire work. If you 10 | need more time, you're doing something wrong. Remember, you have to 11 | do just the first step in refactoring. Don't fix everything. 12 | 13 | Also, if you think that something else must be refactored further, 14 | put your ideas into the description of the pull request. 15 | 16 | Thanks! 17 | 18 | PS. You may want to watch [this lecture](https://www.youtube.com/watch?v=aLaDDoT2v54) too. 19 | --------------------------------------------------------------------------------