Answer the question
In order to leave comments, you need to log in
How to schedule classes for an application a la pastebin.org?
I want to make an analogue of pastebin with the following logic:
1 The user pastes the text
2 The machine determines one of the types
3 Depending on the type, a brief brief is issued.
I write like this (Python code, but I think it is clear to any programmer):
class Paste(object):
def save():
# сериализация и сброс в базу
def guesstype():
# угадать тип пасты
def list():
# список недавних
def __str__():
# показать бриф пасты
class PythonCode(Paste):
def brief():
# найти на гитхабе используемые модули, вывести активность коммитов по ним
def wrapsnippet():
# ...
class MayakovskyPoetry(Paste):
def brief():
# подсчитать слоги в чётных строках
def printhardcoverbook():
# ...
Answer the question
In order to leave comments, you need to log in
You can try a separate resolver class with a single (?) method - to determine the type of text. It can also be a Factory to create the desired class. (I use c# style pseudo code, I think any programmer will also understand)
class Paste {
string Brief() {}
// other methods
}
class PythonCode : Paste {
string Brief() {}
}
class MayakovskyPoetry : Paste {
string Brief() {}
}
class Resolver {
Paste Guess(string text) {}
}
Paste text = Resolver.Guess(userText);
string brief = text.Brief();
guesstype shouldn't be in the base class at all, because it doesn't make sense. You can make an abstract isMatches method in the base class (just an empty method that throws an exception) and overload it in descendants. This method will determine if the given piece of code is suitable for the selected language. Although it would be even better to shove this logic into a separate component.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question