在互联网上发送Android市场公钥(Sending Android market public key across the internet)
通过互联网以原始base64形式发送Android Market公钥是否安全? 如果我这样做会遇到什么问题?
Is it safe to send the Android Market public key in raw base64 form across the internet? What problems could I encounter if I did this?
原文:https://stackoverflow.com/questions/4422428
满意答案
这是一个使用Observer模式将观察者注册到登录系统的示例。 在示例中,我注册了一个观察者,在创建新用户时向管理员发送电子邮件:
首先,我们创建定义observable / observers行为的接口
interface IObserver { //an observer has to implement a function, that will be called when the observable changes //the function receive data (in this case the user name) and also the observable object (since the observer could be observing more than on system) function onUserAdded( $observable, $data ); } interface IObservable { //we can attach observers to the observable function attach( $observer ); }
然后让您的主登录系统实现IObservable,实现attach函数,并保留一组观察者。 在内部,您实现了一个notify函数,在调用它时,迭代数组并通知每个观察者。
你做的是,在创建用户的所有正常行为之后,你调用你的通知函数。
class LoginSystem implements IObservable { private $observers = array(); private function notify( $userName ) { foreach( $this->observers as $o ) $o->onUserAdded( $this, $userName ); } public function attach( $observer ) { $this->observers []= $observer; } public function createUser( $userName ) { //all your logic to add it to the databse or whatever, and then: $this->notify($userName); } }
然后,您创建一个类而不是实现Iobserver。 在onUserAdded函数中,您可以在发生观察事件时执行任何操作。 在这个例子中,我只是将邮件发送到硬编码的电子邮件。 它可能会像你想要的那样复杂。
class NewUserMailer implements IObserver { public function onUserAdded( $observable, $data ) { mail("admin@yoursite.com", "new user", $data); } }
然后,行为就是在创建登录系统之后,您还创建了一个观察者,并且附加到登录系统
$ls = new LoginSystem(); $ls->attach( new NewUserMailer() );
有了这个,每次创建新用户时,邮件都会发送到“admin@yoursite.com”
This is an example that uses the Observer pattern to register observers to your login system. In the example, i register an observer that sends a email to the admin when a new user is created:
First, we create the interfaces that define the behavior of the observable/observers
interface IObserver { //an observer has to implement a function, that will be called when the observable changes //the function receive data (in this case the user name) and also the observable object (since the observer could be observing more than on system) function onUserAdded( $observable, $data ); } interface IObservable { //we can attach observers to the observable function attach( $observer ); }
Then you let your main login system implement IObservable, you implement the attach function, and keep an array of observers. internally, you implement a notify function that when it is called, iterate the array and notify every observer.
What you do, is after all the normal behavior of creating an user, you call your notify function.
class LoginSystem implements IObservable { private $observers = array(); private function notify( $userName ) { foreach( $this->observers as $o ) $o->onUserAdded( $this, $userName ); } public function attach( $observer ) { $this->observers []= $observer; } public function createUser( $userName ) { //all your logic to add it to the databse or whatever, and then: $this->notify($userName); } }
Then, you create a class than implements Iobserver. in the onUserAdded function, you do whatever you want to happen when the observed event occurs. In this example i just send a mail to a hardcoded email. It could be as complex as you want.
class NewUserMailer implements IObserver { public function onUserAdded( $observable, $data ) { mail("admin@yoursite.com", "new user", $data); } }
Then, the behavior is just, after creating the loginsystem, you also create an observer, and attach is to the login system
$ls = new LoginSystem(); $ls->attach( new NewUserMailer() );
With this, everytime a new user is created, a mail will be sent to "admin@yoursite.com"
相关问答
更多这段代码是否遵循观察者模式?(Does this code follow Observer pattern?)
如何在PHP中实现完整的Observer模式(How to implement a full Observer pattern in PHP)
观察者模式的策略?(strategy for observer pattern?)
为什么在观察者模式中使用接口?(Why interface is used in observer pattern?)
MVVM本身是Observer模式吗?(Is MVVM itself a Observer pattern?)
如何在PHP登录系统中使用Observer模式?(How to use the Observer pattern in PHP login system?)
使用Flash事件系统或构建自己的观察者设计模式?(Use Flash Event System or build own Observer Design Pattern?)
Javafx和Observer模式 - 更新UI(Javafx and the Observer pattern - updating a UI)
Observer模式如何减少耦合?(How does the Observer pattern reduce coupling?)
观察者设计模式问题(observer design pattern question)
相关文章
更多android 集成所有分享平台
《发布Joomla! 网站到互联网:宁皓网》(Launch your Joomla! site to the internet @ ninghao.org)开放式课程[MOV]
Android精品软件汇总(不断更新)
Android开发_微信分享功能
疯狂Android讲义
Android照片墙应用实现,再多的图片也不怕崩溃
Android 再多图片也不会出现OOM
android---TextView赋值问题
android googlemap问题,求帮助...
Android应用加入微信分享
最新问答
更多sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
湖北京山哪里有修平板计算机的
SimplePie问题(SimplePie Problem)
在不同的任务中,我们可以同时使用多少“上下文”?(How many 'context' we can use at a time simultaneously in different tasks?)
HTML / Javascript:从子目录启用文件夹访问(HTML/Javascript: Enabling folder access from a subdirectory)
为什么我会收到链接错误?(Why do I get a linker error?)
如何正确定义析构函数(How to properly define destructor)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!