我只是想知道,如何隐藏特殊
__.*__
Run Code Online (Sandbox Code Playgroud)
python*中的方法?特别是我正在使用带tab-completion的交互式python解释器,我想只显示我的模块公开的方法...
谢谢,
/ myyn /
*(至少来自使用python shell的用户)
现在看起来像这样:
h[2] >>> Q.
Q.ALL( Q.__delattr__( Q.__getattribute__(
Q.__package__ Q.__sizeof__( Q.find_values(
Q.json
Q.DEFAULT_CONDITION( Q.__dict__ Q.__hash__(
Q.__reduce__( Q.__str__( Q.get_loops_total_platform(
Q.jsonlib
Q.SUCCESSFUL( Q.__doc__ Q.__init__(
Q.__reduce_ex__( Q.__subclasshook__( Q.get_platforms(
Q.memoize(
Q.__all__ Q.__file__ Q.__name__
Q.__repr__( Q.cached_open( Q.get_snippets(
Q.__class__( Q.__format__( Q.__new__(
Q.__setattr__( Q.find_results( Q.get_subjects(
h[2] >>> Q.
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像:
h[2] >>> Q.
Q.ALL( Q.find_values( Q.json
Q.DEFAULT_CONDITION( Q.get_loops_total_platform(
Q.jsonlib Q.SUCCESSFUL( Q.get_platforms(
Q.memoize( Q.cached_open( Q.get_snippets(
Q.find_results( Q.get_subjects(
h[2] >>> Q.
Run Code Online (Sandbox Code Playgroud) 这是第一个问题:
这可能吗?我从Joe Wrobel的工作中获取灵感(减少了被遗忘的Codeplex项目).在这里,您完成了为提供程序创建配置文件的工作,并为其创建强类型的工作,有效地为Profile类创建了一个Facade.
现在是背景故事!
我真的不喜欢魔法弦.它们非常糟糕,在更新应用程序时可能会导致严重的问题.在PHP和ColdFusion等语言中工作之后,我知道很容易将它们放入应用程序并忘记它们,直到您需要更改它们.然后你必须追捕它们的每一个变化并相应地改变它们.
如果您遵循"开箱即用"的应用程序模板,.NET实际上并没有那么好.很多例子都使用web.config中的appsetting来存储各种设置.这确实是一个存储的好地方,非常适合大多数应用程序.然而,当您开始直接调用这些问题时,问题就开始出现了 - 例如ConfigurationManager.AppSettings["MyAppSetting"].然后,当你回到使用魔术字符串时,你并没有比PHP用户更好.
这就是外墙进来的地方.外墙提供了一种在一个地方从魔术字符串创建强类型对象的方法,并让开发人员从应用程序的其余部分引用它.
现在,我没有使用web.config来包含我的appsettings,而是使用数据库来保存它们.在应用程序启动时,将检索名称/值组合,然后将其顺序添加到ConfigurationManager.AppSettingsvia Set.没什么大不了的(除了我之前的问题!).
这个"应用程序外观"可以通过我的数据层,服务层和表示层访问,并保存应用程序模式,使用yada yada yada的服务端点,并限制必须寻找许多魔法字符串,最多两个魔法strings - facade中的一个(名称),以及创建点中的另一个(名称和值)(对我来说是db).
这个门面类最终会变得非常大,我最终会厌倦不得不更新它们.
所以我想要做的是拥有一个ApplicationFacade类,每次构建完成后都会自动生成.现在又回到了开始......这可能吗?
我已经读完http://addyosmani.com/largescalejavascript/上的精彩文章
本文将介绍如何将模块,外观和介体组合在一起以用于JavaScript应用程序.
我可以编写文章解释的内容,但我不明白为什么我需要使用facade来访问中介.
我想我可以直接从我的模块访问调解器.
请建议我..
PS:这是一个有效的问题吗?
由于这里关于这个主题的许多问题证明了这一点,所以拿一本字典是一个非常常见的任务,有一个相当不错的解决方案:
{k:v for k,v in dict.viewitems() if some_test(k,v)}
Run Code Online (Sandbox Code Playgroud)
但是这会创建一个新的字典,并带有自己的映射.对于许多操作,只有原始字典的不可变视图(即它不支持视图上的赋值或删除操作)会很好.实现这样的类型可能很容易,但是增加本地实用程序类并不好.
所以,我的问题是:是否有内置的方式来获得这样的"子集视图"?或者是否有第三方库(最好通过PyPi提供)提供这种实用程序的良好实现?
我有一个Str::random()我想测试的类。
但是当我Str::shouldReceive('random')在我的测试中使用时,我得到一个 BadMethodCallException 说该方法 shouldReceive 不存在。
我还尝试直接模拟该类并将其绑定到 IOC,但它一直在执行原始类,生成一个随机字符串而不是我在模拟上设置的返回值。
$stringHelper = Mockery::mock('Illuminate\Support\Str');
$this->app->instance('Illuminate\Support\Str', $stringHelper);
//$this->app->instance('Str', $stringHelper);
$stringHelper->shouldReceive('random')->once()->andReturn('some password');
//Str::shouldReceive('random')->once()->andReturn('some password');
Run Code Online (Sandbox Code Playgroud) 背景:
我有一个REST服务让我们说CustomerService现在有一个方法getCustomer(id, country).现在的要求是,根据国家/地区,我必须执行不同的业务逻辑,例如访问不同的数据库或一些自定义规则,然后报告我收到了这样的请求.
首先根据国家我使用Factory模式解决不同的实现,如下所示:
所有国家/地区实施的通用接口
public Interface CustomerServiceHandler{
Cusomer getCustomer(String id, String country);
}
Run Code Online (Sandbox Code Playgroud)
然后工厂作为
public class CustomerServiceHandlerFactory{
public CustomerServiceHandler getHandler(String country){...};
}
Run Code Online (Sandbox Code Playgroud)
使用Facade实现详细信息
请注意,此外观是从REST类调用的,即CustomerService
public CustomerServiceFacade{
public Customer getCustomer(String id, String country){
//use factory to get handler and then handler.getCustomer
Customer customer = factory.getHandler(country).getCustomer(id,country);
//report the request
reportingService.report('fetch-customer',....);
return customer;
}
}
Run Code Online (Sandbox Code Playgroud)
按照SRP(单一责任原则),这个立面并没有实现单一目标.它正在抓住客户以及报告收到此类请求.所以我想到装饰模式如下.
使用Decorator模式实现:
//this is called from Rest layer
public ReportingCustomerHandler implements CustomerServiceHandler{
//this delegate is basically the default implementation and has factory …Run Code Online (Sandbox Code Playgroud) 因此,我正在努力创建我的第一个服务提供商和Laravel的免费Facade.
服务提供者:
<?php namespace Jbm\Providers;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Jbm\Helpers\ReportGenerator;
class ReportGeneratorServiceProvider extends BaseServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->bind('Jbm\Helpers\Contracts\ReportGeneratorContract', function($app){
return new ReportGenerator();
});
}
/**
* Add the Cors middleware to the router.
*
* @param Kernel $kernel
*/
public function boot(Request $request, …Run Code Online (Sandbox Code Playgroud) 当我对它进行try/catch时DB::Connection()->getPdo();,我得到错误没有设置外观根.Schema在我尝试添加try/catch之前,我相信它也发生在外墙上.当然,测试目录在app目录之外,我觉得它与它有关,但我还没有成功搞清楚.
以下是发生这种情况的测试类:
<?php
namespace Tests\Models;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use App\Models\Discussion;
use App\User;
use Business\Database\Model;
use Illuminate\Database\Schema\Blueprint;
use Tests\TestCase;
class DiscussionModelTest extends TestCase
{
/**
* Create the tables this model needs for testing.
*/
public static function setUpBeforeClass()
{
try {
DB::connection()->getPdo();
} catch(\Exception $e) {
die($e->getMessage());
}
Schema::create('discussions', function (Blueprint $table) {
$table->integer('id');
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
Schema::create('users', function (Blueprint $table) {
$table->integer('id');
});
}
}
Run Code Online (Sandbox Code Playgroud) I have a dynamic form component that receive many services using angular DI system:
export class CityFormComponent<DataModel> extends BaseForm<DataModel>
implements OnInit {
constructor(
protected appConfig: AppConfig,
protected httpService: CityService,
protected snackBar: MatSnackBar,
protected componentFactoryResolver: ComponentFactoryResolver,
private cdr: ChangeDetectorRef,
protected route: ActivatedRoute,
protected router: Router) {
super(appConfig, httpService, snackBar, componentFactoryResolver, route, router);
}
Run Code Online (Sandbox Code Playgroud)
Is it a good practice to encapsulate all of the services except httpService in a wrapper facade service and then define methods that the form component needs and …
我尝试在标准 AbstractFacade(由 NetBeans 生成)的创建和编辑方法上添加参数约束配置(bean 验证)。
所以我尝试:
@Override
public void create(@WkTeilnahmePlanedResult WkTeilnahme entity) {
super.create(entity);
}
Run Code Online (Sandbox Code Playgroud)
这返回了消息
将覆盖另一个方法的方法部署到 Glassfish 4 时不得更改参数约束配置
所以接下来的尝试是
@Override
public void create(WkTeilnahme entity) {
checkedCreate(entity);
}
private void checkedCreate(@WkTeilnahmePlanedResult WkTeilnahme entity) {
super.create(entity);
}
Run Code Online (Sandbox Code Playgroud)
部署没有任何问题......但验证器从未被调用。
你能告诉我为什么吗?
顺便提一句:
@Override
public void create(WkTeilnahme entity) {
throw new UnsupportedOperationException(
"Create not supported! Use checkedCreate() instead!");
}
public void checkedCreate(@WkTeilnahmePlanedResult WkTeilnahme entity) {
super.create(entity);
}
Run Code Online (Sandbox Code Playgroud)
这可行,但并不是很酷!
facade ×10
laravel ×3
java ×2
python ×2
angular ×1
appsettings ×1
asp.net ×1
c# ×1
decorator ×1
dictionary ×1
hide ×1
jakarta-ee ×1
javascript ×1
laravel-5 ×1
laravel-5.5 ×1
mediator ×1
mockery ×1
module ×1
php ×1
phpunit ×1
t4 ×1
typescript ×1
unit-testing ×1