エンタープライズ アプリケーションでは、ビジネス要件に応じてさまざまな実装が行われます。実行時には、特定の条件に基づいてこれらのうち 1 つを実行する必要があります。一般的な例としては、並べ替えアルゴリズム、データ暗号化、通知サービス、認証サービス、支払いサービスなどがあります...
if-else 条件を使用する代わりに、戦略設計パターンを使用して実装できます。戦略設計パターンは、実行時にさまざまな実装を実行/使用するのに役立ちます。この戦略は、コードの再利用性、柔軟性、関心事の分離、および拡張性を提供します。
さまざまなチャネル/クライアントからのリクエストを受信する統合認証サービスを開発したとします。実行時には、構成に基づいて、認証目的に使用する実装を決定する必要があります (これはリクエスト転送の場合もあります)。実装には、okta、Azure Ad、または独自の IAM を使用できます。
注: プロバイダーを独立したモジュールとして実装し、それを依存関係としてメイン プロジェクトに追加する必要があります。
戦略インターフェース
public interface Authentication { AuthenticationRes authentication(AuthenticationReq authenticationReq); OtpDevicesRes otpDevices(OtpDevicesReq otpDevicesReq); SendOtpRes sendOtp(SendOtpReq sendOtpReq); VerifyOtpRes verifyOtp(VerifyOtpReq verifyOtpReq); }
具体的な戦略
@Component("oktaAuthentication") @Slf4j public class OktaAuthentication implements Authentication { -------------- -------------- -------------- } @Component("ferAuthentication") @Slf4j public class FerAuthentication implements Authentication { -------------- -------------- -------------- } @Component("eapAuthentication") @Slf4j public class EapAuthentication implements Authentication { -------------- -------------- -------------- }
サービス
@Service @Slf4j public class AuthenticationService { public Map<string authentication> authenticationProvidersMap; public Set<string> availableAuthProviders; public AuthenticationService(Map<string authentication> authenticationProvidersMap) { this.authenticationProvidersMap = authenticationProvidersMap; this.availableAuthProviders = this.authenticationProvidersMap.keySet(); log.info("Available Auth providers:{}", this.availableAuthProviders); } public AuthenticationRes getAuthentication(AuthenticationReq authenticationReq, ClientDetails clientDetails) { //This method will identify authentication provider based on client details // and returns oktaAuthentication/eapAuthentication/ferAuthentication String authProvider = getAuthProviderDetails(clientDetails); if (this.availableAuthProviders.contains(authProvider)) { return this.authenticationProvidersMap.get(authProvider) .authentication(authenticationReq); } else { throw new AuthProviderUnavailable(authProvider); } } public String getAuthProviderDetails(ClientDetails clientDetails) { // implement your business logic to return the provider that need to be used. } } </string></string></string>
ご質問がございましたら、コメント欄に質問を残してください。
以上が春の戦略設計パターンの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

JavaremainsagoodlanguagedueToitscontinuousevolution androbustecosystem.1)lambdaexpressionsenhancecodereadability andenableFunctionalprogramming.2)streamsalowsolowsolfisitydataprocessing、特に特にlagedatasets.3)硬化系系統系系統系系統系系統

Javaisgreatduetoitsplatformindependence、robustoopsupport、extensiveLibraries、andstrongCommunity.1)PlatformentepenteviajvMallowsCodeTorunonVariousPlatforms.2)oopeatureSlikeEncapsulation、遺伝、およびポリモ系系統型皮下皮質皮下Rich

Javaの5つの主要な特徴は、多型、Lambda Expressions、StreamSapi、ジェネリック、例外処理です。 1。多型により、さまざまなクラスのオブジェクトを一般的なベースクラスのオブジェクトとして使用できます。 2。Lambda式は、コードをより簡潔にし、特にコレクションやストリームの処理に適しています。 3.ストリームサピは、大規模なデータセットを効率的に処理し、宣言操作をサポートします。 4.ジェネリックは、タイプの安全性と再利用性を提供し、型刻印中にタイプエラーがキャッチされます。 5.例外処理は、エラーをエレガントに処理し、信頼できるソフトウェアを作成するのに役立ちます。

java'stoputuressificlynificlytallysperformanceandscalability.1)object-oriented-principleslikepolymorphismenabledscalablecode.2)garbagecolectionAutomateMemorymarymanagemenateButcancausElatenceSuses.3)

JVMのコアコンポーネントには、クラスローダー、runtimedataarea、executionEngineが含まれます。 1)クラスローダーは、クラスとインターフェイスの読み込み、リンク、初期化を担当します。 2)runtimedataareaには、Methodarea、Heap、Stack、Pcregister、Nativemethodstackが含まれています。 3)ExecutionEngineは、Bytecodeの実行と最適化を担当する通訳、JitCompiler、GarbageCollectorで構成されています。

Java'ssafetyandsecurityarebolteredby:1)stronttyping、whathspreventype-relatederrors; 2)自動メモリ管理viagarbagececollection、3)サンドボクシング、分離コードフロムシェシシステム;

Javaoffersseveralkeyfeaturesthatenhancecodingskills:1)Object-orientedprogramingallowsmodelingreal-worldentities、explifiedBypolymorphism.2)例外ハンドリングプロビッドログスロルマニネーション

jvmisacrucialcomponentthaturunsjavacodebytrantingintiTomachine特異的インストラクション、パフォーマンス、セキュリティ、およびポータビリティに影響を与えます


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 中国語版
中国語版、とても使いやすい

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール
