如何从基类调用类(框架) [英] how to invoke class(frame) from Base Class

查看:94
本文介绍了如何从基类调用类(框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hiii
我在设计专家系统中检测框架(类)中的错误.我具有3层体系结构.业务层是基类..ZipCode,SSN,Name等是派生类(框架)..基类中有一个虚拟方法,例如Check_Format(与正则表达式匹配框架(邮政编码,ssn等)值(保存在数据库表中)与正则表达式匹配),并且该方法在派生类中被覆盖.
现在我只是想要例如,如果ZipCode值与正则表达式匹配,则调用ZipCode框架,如果SSn值与之匹配,然后SSn自动调用..我不希望任何硬编码我想要的所有东西都是动态的. soo plz helppp mee
在此先感谢

hiii
i m designing expert system which detect errors in frames(classes).i have 3 layerd architecture..business layer is base class..ZipCode,SSN,Name etc are derived classes(frames)..there is a virtual method in Base Class e.g Check_Format(which match the frame(zipcode,ssn etc)value(save in database table)with regular expression)and that method is overrides in derived class..

now i just want that e.g if ZipCode value matches with regular expression then the ZipCode frame invoke and if SSn value matches then SSn invoke automatically..i donot want any hardcoding every thing i want is dynamic..
soo plz helppp mee
thanks in advance

推荐答案

只有一个工厂,然后在工厂方法中传递您的regex模式.Check_format应该是静态方法.因此,如果结果为true,则工厂方法将调用每种类型的check_format方法,然后将给出该类型的类的实例.

但是可能有问题.调用方如何知道它将获得哪种类型的对象?工厂可以产生父类型,但是可以保留特定类型子实例的实际实例.在那种情况下,父母需要拥有孩子需要拥有的所有方法(可能是抽象的).然后,工厂返回父代的类型,但保留子代的实例.所有必需的方法都可以通过父类获得.在这种情况下,接口将是理想的.
just have a factory and then in the factory method pass your regex pattern.The Check_format should be static method. So the factory method call each type''s check_format method if results true then it give out the instance of that type of class.

But there may be a problem. How the caller know which type of object it is going to get?. The factory can produce a type of the parent, but holds actual instance of a child of a specific type. In that case the parent need to have all the methods (may be abstract) which a child need to have. Then the factory returns a type of the parent but holds instance of the child. All the methods necessary will be available through the parent class. An interface would be ideal in this case.


您的问题并不清楚,但是如果您想从基类本身调用基方法或重写的方法,请使用这个:

Your quetion ins''t all that clear, but if you want to call a base method or an overridden method from the base class itself, use this:

this.MethodName();



如果要使用基类中的重写方法,请使用以下方法:



If you want to use the overriden method from the base class, use this:

MethodName();


这篇关于如何从基类调用类(框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆