在抽象类中强制执行方法执行顺序(Enforce method execution order in Abstract Class)
我有一个商业案例需要按顺序发生3件事情:
- 下载()
- 处理()
- 上传()
现在,Abstract Class FileTransfer为1. downloadFiles()和3. upload()提供实现,但不提供2. process() - 子类(如MusicFileTransfer或VideoFileTransfer或PDFFileTransfer)将在2.进程中执行不同的操作)阶段。
因此,抽象类似乎很清楚:
public abstract class FileTransfer { public void download() { // implementation provided } public abstract void process(); // implementation not provided public void upload() { // implementation provided } }
但是有一个问题 - MusicFileTransfer在下载()或任何其他顺序之前调用process()将永远 不会有好的时机。 该过程必须始终为1. download(),2. process(),然后3. upload()。
所以我想像这样:
public void doTransfer() { // private methods since we want to enforce this order of execution download(); // implem provided process(); // abstract method upload(); // implem provided }
在FileTransfer中包装这三个调用。 但为了让子类MusicFileTransfer覆盖process()...它必须是public或protected(不是私有的)。
我应该如何解决这个泡菜? 有一个公共的doTransfer() 和一个公共进程(),只是确保process()永远不会被调用? 或者抛弃doTransfer()并希望订单总是正确的?
I have a business case in which 3 things need to happen, in sequence:
- download()
- process()
- upload()
Now, the Abstract Class FileTransfer provides implementation for 1. downloadFiles() and 3. upload(), but not 2. process() -- child classes (like MusicFileTransfer or VideoFileTransfer or PDFFileTransfer) will do different things in the 2. process() stage.
So it seems clear to make the abstract class like so:
public abstract class FileTransfer { public void download() { // implementation provided } public abstract void process(); // implementation not provided public void upload() { // implementation provided } }
But one issue -- There will never ever be a time in which it is okay for, say, MusicFileTransfer to call process() before download() or any other order. The process must always be 1. download(), 2. process(), then 3. upload().
So I imagine something like:
public void doTransfer() { // private methods since we want to enforce this order of execution download(); // implem provided process(); // abstract method upload(); // implem provided }
in FileTransfer to wrap around these three calls. But in order for the child class MusicFileTransfer to override process() ... it must be public or protected (not private).
What should I do to work around this pickle? Have a public doTransfer() and a public process() and just make sure process() is never ever called? Or do away with the doTransfer() and hope that the order is always correct?
原文:https://stackoverflow.com/questions/26125721
最满意答案
您不能为函数的参数指定
NUMBER
精度和缩放比例。 只需声明如下:CREATE OR REPLACE FUNCTION MyFunction2(LINE_ID NUMBER)
You can't specify
NUMBER
precision and scale for a function's parameter. Just declare it like this:CREATE OR REPLACE FUNCTION MyFunction2(LINE_ID NUMBER)
相关问答
更多-
您可以使用TO_NUMBER函数将varchar2转换为数字: 从MyTable中删除TO_NUMBER(数字)<7 You can use TO_NUMBER function to convert varchar2 to number: delete from MyTable where TO_NUMBER(Number)<7
-
尝试这个 (没有测试,因为我目前没有oracle连接) CREATE OR REPLACE TRIGGER trg_ta_totals BEFORE INSERT OR UPDATE ON T_A FOR EACH ROW DECLARE vnum number; BEGIN IF instr(:NEW.total,'p') > 0 THEN vnum:=TO_NUMBER(SUBSTR(:NEW.total,0,LENGTH(:NEW. ...
-
我通过在更新步骤之前创建KEY_LEN为LEN(键)的派生列来解决问题。 然后我在更新中使用它作为第三个参数: UPDATE Table SET column1 = ? where KEY = SUBSTR(?,0,?) I've resolved the problem by creating the derived column with KEY_LEN as LEN(key) before the update step. Then I've used it in update as the thi ...
-
基于存储在varchar2中的选择,只需要稍微不同的语法即可打开游标: CREATE OR REPLACE PROCEDURE ME(sqlstmt IN VARCHAR2) AS C1 SYS_REFCURSOR; vAlphabet varchar2(100); vNumber number; BEGIN OPEN C1 FOR sqlstmt; LOOP FE ...
-
Oracle SQL:将Varchar2转换为Number并处理Null(Oracle SQL: Convert Varchar2 to Number and handle Nulls)[2022-12-04]
此时转换可能会失败。 0.33不是所有语言的有效数字。 您可以将该点明确指定为小数分隔符: to_number(cuser1, '99999.999') 也许你甚至不得不削减空白: to_number(trim(cuser1), '99999.999') 但仍有可能存在违反该模式的价值观。 然后WHERE子句可能只有助于转换有效数字。 例如: where regexp_like(cuser1, '^[[:digit:]]*\.{0,1}[[:digit:]]*$') or cuser1 is null ... -
Clob列到varchar2(Clob column to varchar2)[2024-01-22]
我找到答案:DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL(u.object_type,u.object_name),2000,1)为“DLL_INFORMATION”。 谢谢,顺便说一下 I find the answer: DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL(u.object_type, u.object_name), 2000,1) as "DLL_INFORMATION". Thanks, btw -
您不能为函数的参数指定NUMBER精度和缩放比例。 只需声明如下: CREATE OR REPLACE FUNCTION MyFunction2(LINE_ID NUMBER) You can't specify NUMBER precision and scale for a function's parameter. Just declare it like this: CREATE OR REPLACE FUNCTION MyFunction2(LINE_ID NUMBER)
-
你的maven条目看起来很奇怪。 您正在尝试使用oracle 12c增强功能但仍然使用来自oracle 10
10.3.6.0 jar。 此外,如果您的jdk高于jdk6,您可能必须使用ojdbc7 Your maven entry looks strange. You are trying to utilize oracle 12c enhancement but still, you are using jar from oracle 1010. ... -
编辑 (稍后,但这属于顶部) - DUH! 如果你将8比作“3到15之间”但AS STRINGS会怎么样? 如果您将它们命名为字符串,则在3之后和15之后! 你确实需要将所有内容都作为数字而不是字符串。 (此外,如果你这样写, something between '3' and '15' ,你永远不会得到任何行 - 因为字符串'3'大于'15'并且Oracle在使用中不灵活BETWEEN;较低(较小)的数字,日期或字符串必须始终排在第一位。) 原始答案: 确切地找出数据库中存储的内容的一种方法是使用DUMP ...
-
ALL_TABLES和ALL_TAB_COLUMNS应该足以检索表结构上的任何元信息。 根据文档 ALL_TAB_COLUMNS.DATA_LENGTH显示以字节为单位的长度和ALL_TAB_COLUMNS.CHAR_LENGTH - 根据应用于列的长度语义的字符。 尝试在查询中代替DATA_LENGTH DECODE(char_used,'C',char_lenght,data_lenght) data_length 另外,请注意select * from database_properties wher ...