当使用特定的数据库如sql server时,我们是否必须安装和配置odbc?(when using a specific database such as sql server,do we have to install and configure odbc?)
当使用特定的数据库如sql server时,我们是否必须安装和配置odbc?
而我的另一个问题是为什么cant thrift / avro / rest / protobuf与rdbms一起使用,它们是服务,为什么它们只用于nosql dbs? 我正在阅读专业的nosql书籍,并且列出了不同的nosql db访问方法,它们被列为nosql db访问方法,但当我用Google搜索它们时,我看到它们是用于序列化数据的服务等等(每个都是因为某事。
提前致谢。
when using a specific database such as sql server,do we have to install and configure odbc?
and my other question is why cant thrift/avro/rest/protobuf be used with rdbms,they are services,why are they just used with nosql dbs? I am reading professional nosql book,and there is a list of different nosql db access methods,and they are listed as nosql db access methods,but when I googled them I saw they are services for serializing datas and so on(each of them is for sth).
thanks in advance.
原文:https://stackoverflow.com/questions/18596448
最满意答案
简单,简单,非魔法的方法是在
SpecialEffects
对象中存储方法名称,根据您想要发生的任何事情设置它,并从sound()
调用它。package SpecialEffects; sub new { my $type = shift; my %options = @_; my $self = {}; bless $self, $type; if($options{config} eq 'a') { $self->{sound_method} = 'fizz'; } elsif($options{config} eq 'b') { $self->{sound_method} = 'clonk'; } return $self; } sub sound { my $self = shift; my $method_name = $self->{sound_method}; $self->$method_name(); } sub fizz { print "fizz\n"; } sub clonk { print "clonk\n"; }
如果您想要更精灵,可以像方法名一样轻松地存储和使用coderefs。
package SpecialEffects; sub new { my $type = shift; my %options = @_; my $self = {}; bless $self, $type; if($options{config} eq 'a') { $self->{sound_code} = $self->can('fizz'); } elsif($options{config} eq 'b') { $self->{sound_code} = $self->can('clonk'); } return $self; } sub sound { my $self = shift; my $code = $self->{sound_code}; $self->$code(); }
The simple, easy, non-wizardry way is to just store a method name in your
SpecialEffects
object, set it according to whatever you want to happen, and call it fromsound()
.package SpecialEffects; sub new { my $type = shift; my %options = @_; my $self = {}; bless $self, $type; if($options{config} eq 'a') { $self->{sound_method} = 'fizz'; } elsif($options{config} eq 'b') { $self->{sound_method} = 'clonk'; } return $self; } sub sound { my $self = shift; my $method_name = $self->{sound_method}; $self->$method_name(); } sub fizz { print "fizz\n"; } sub clonk { print "clonk\n"; }
You can store and use coderefs about as easily as method names, if you want to be more wizardly.
package SpecialEffects; sub new { my $type = shift; my %options = @_; my $self = {}; bless $self, $type; if($options{config} eq 'a') { $self->{sound_code} = $self->can('fizz'); } elsif($options{config} eq 'b') { $self->{sound_code} = $self->can('clonk'); } return $self; } sub sound { my $self = shift; my $code = $self->{sound_code}; $self->$code(); }
相关问答
更多-
Ruby中的方法:对象与否?(Methods in Ruby: objects or not?)[2023-03-24]
方法是Ruby语法的基本部分,但它们不是Ruby程序可以操作的值。 也就是说, Ruby的方法不是字符串,数字和数组的对象。 但是,可以获取表示给定方法的Method对象,我们可以通过Method对象间接调用方法。 从Ruby编程语言 : 替代文字http://ecx.images-amazon.com/images/I/517LDwIEYwL._SL75_.jpg Methods are a fundamental part of Ruby's syntax, but they are not value ... -
如何使用调用相同方法的2个不同对象来定义类(How to define classes using 2 different objects calling the same methods)[2023-07-21]
有几种方法可以解决这个问题。 我建议你写一个ftp客户端实现的接口IWorkingDirectory,它有一个方法 GetWorkingDirectory(string dir). IRemoteCopy的Connect方法的界面将变为: IWorkingDirectory Connect(string Host, int Port, string Username, string Password, string Fingerprint); 然后你可以简化调用 public string GetWo ... -
您已经实现了Anemic Domain Model反模式。 类应该实现他们需要的方法,这不会破坏SRP,但是无论如何,恕我直言。 You've implemented the Anemic Domain Model antipattern. Classes should implement the methods that they need, that doesn't break SRP, but IMHO SRP is way over rated anyway.
-
我可以将对象方法替换为不同对象上的不同方法吗?(Can I alias an object method to different methods on different objects?)[2023-08-05]
简单,简单,非魔法的方法是在SpecialEffects对象中存储方法名称,根据您想要发生的任何事情设置它,并从sound()调用它。 package SpecialEffects; sub new { my $type = shift; my %options = @_; my $self = {}; bless $self, $type; if($options{config} eq 'a') { $self->{sound_method} = ... -
假设当前代码的结构方式是正确的,每次调用update_image()方法时都会分配IMAGE_MAPPER 。 现在,因为这是一个不随时间变化的静态映射,从功能的角度来看这不是问题 - 它不像你重置一个应该在调用update_image()之间跟踪的值。 性能方面,在这种特殊情况下,缺点也绝对可以忽略不计。 但从纯逻辑角度来看,将这种映射作为类属性可能是有意义的: class Room1(Room): IMG_MAPPING = {(0, 0, 0) : 0, ...
-
同一类的不同对象的同步方法[重复](Synchronized methods of different objects of the same class [duplicate])[2021-12-15]
依靠。 如果方法是静态的,那么它们在类对象上同步并且交错是不可能的。 如果它们是非静态的,那么它们就可以在this上同步并且可以进行交错。 以下示例应阐明行为。 import java.util.ArrayList; import java.util.List; class Main { public static void main(String... args) { Listthreads = new ArrayList (); System.ou ... -
我可能会为Statistics创建一个单独的类,并使用它像这样: $stats = new Statistics($user_id); $stats->add_product($product_id); I would probably create a separate class for Statistics and use it like this: $stats = new Statistics($user_id); $stats->add_product($product_id);
-
我建议只使用Vector()类和布尔normalized实例属性。 此外,在normalize方法中,您使用的是x , y和z,但这些变量未定义,您甚至无法使用self读取它们。 我建议的代码: from math import sqrt class Vector(object): def __init__(self, x, y, z, normalized=False): self.v = [x, y, z] if normalized in [True ...
-
检查后,您可以(并且应该)安全地投射对象,以便根据需要使用它们。 if (x instanceof Comparable && y instanceof Comparable) { Comparable c1 = (Comparable) x; Comparable c2 = (Comparable) y; if(c1.compareTo(c2) < 0){ //do stuff } } After checking you can (an ...
-
假设别名函数是内联的 - 它们应该给出大小。 不应该有任何性能开销。 如果编译器决定省略功能代码并内联所有调用,则代码大小也不会增加。 (我指的是bar_alias1()内联,如果它很大, bar()本身不一定会内联。) 但是,如果功能是虚拟的,则不适用。 在C中,我会更直接地使用预处理器执行此操作,但我不确定它在C ++中是否合适。 Assuming the aliased functions are inlined - and they should given the size. There shou ...