مطالب
طراحی شیء گرا: OO Design Heuristics - قسمت چهارم

Dynamic Semantics

Objectها علاوه بر داده و رفتار به عنوان توصیفات ثابت، در زمان اجرا دارای یک Local State (‏‏a snapshot) از مقادیر داینامیک مربوط به اعضای داده‌ای خود، می‌باشند. مجموعه تمام حالاتی که وهله‌های یک کلاس می‌توانند بین آنها گذر (transition) داشته باشد، dynamic semantics مربوط به کلاس نامیده می‌شود و به وهله‌های کلاس این امکان را می‌دهند تا به یک پیغام مشابه رسیده و در زمان‌های مختلف از چرخه زندگی خود، به اشکال مختلف پاسخ دهند.

Method junk for the class X 
if (local state #1) then
do something
else if (local state #2) then
do something different
End Method

بخش اصلی هر طراحی شیء گرا، dynamic semantics وهله‌ها می‌باشد. dynamic semantics هر کلاسی باید در قالب یک دیاگرام state-transition مستند شود. شکل زیر dynamic semantics پروسه‌های موجود در یک سیستم عامل را در قابل یک دیاگرام حالت نمایش می‌دهد. این پروسه‌ها توانایی این را دارند که در هر کدام از حالات: runnable، current process، blocked، sleeping و یا در حالت exited، قرار داشته باشند. همچنین به عنوان مثال، یک پروسه زمانی می‌تواند در حالت current process قرار گیرد که حتما قبلا در حالت runnable قرار داشته باشد. این اطلاعات برای ایجاد تست برای کلاس‌ها و وهله‌های آنها می‌تواند مفید واقع شود.

شکل 2.8 State-transition diagram notation 

برخی از طراحان به طور تصادفی، dynamic semantics یک کلاس را به عنوان static semantics آن کلاس مدل می‌کنند. به عنوان مثال اگر color یکی از اعضای داده ای (data member) کلاس توپ باشد و بعد از وهله سازی از کلاس توپ، color آن بازهم قابل تغییر باشد، منظور اینکه توپ آبی به عنوان یک وهله از کلاس توپ در زمان حیات خود تغییر رنگ دهد، اصطلاحا می‌گویند: color جزء dynamic semantics کلاس توپ می‌باشد. با توجه به توضحیاتی که داده شد، حال اگر طراحی برای هر رنگ توپ یک کلاس جدا در نظر گرفته باشد، dynamic semantics را به عنوان static semantics مدل کرده و به احتمال زیاد ما را به سمت ایجاد مشکل Class Proliferation (ازدیاد کلاس ها) سوق خواهد داد.

Abstract Classes

به سوالات زیر توجه کنید:

  • آیا هرگز میوه خورده‌اید؟
  • آیا هرگز پیش غذا خورده‌اید؟ 
  • آیا هرگز دسر خورده‌اید؟ 
اکثر مردم به این سوالات جواب «بله» را خواهند داد.
حال با توجه به سوالات «مزه غذا چطور بود؟ دسری که خوردید، چه تعداد کالری داشت؟ هزینه پیش غذایی که خوردید چقدر بود» پاسخ چه خواهد بود؟
من (نویسنده) ادعا میکنم که هیچ کسی تا به حال میوه نخورده است. بیشتر مردم، سیب، موز و پرتقال خورده‌اند؛ میوه‌ی قرمز رنگی به ارزش 3 پوند را نخورده‌اند.

شبیه به این مسئله برای زمانی است که گارسون رستوران از شما سوال می‌کند: «برای شام چه چیزی میل دارید» و شما جواب می‌دهید: «یک پیش غذا، یک غذای اصلی و یک دسر». در این حالت چون شما دقیقا مشخص نکرده‌اید چه نوعی می‌خواهید، گارسون، مات و مبهوت خواهد ماند. همه می‌دانیم که چیزی تحت عنوان میوه، پیش غذا و یا وهله دسر در واقعیت وجود ندارد؛ بله این عبارات اطلاعات مفیدی را تسخیر می‌کنند. اگر من در دستم یک ساعت زنگی گرفته و از شما می‌پرسیدم: «نظرتان در مورد میوه من چیست؟»؛ بدون شک فکر می‌کردید من دیوانه شده‌ام. حال اگر در دستم سیبی گرفته و سوال قبلی را می‌پرسیدم، این بار از نظر شما من یک شخص عاقل بودم.
با وجود اینکه نمی‌توان از میوه وهله سازی کرد، اما اطلاعات مفیدی را تسخیر می‌کند. در واقع میوه، یک کلاسی (concept) است که دانشی از نحوه وهله سازی وهله هایش به وسیله Type پیاده ساز خود، ندارد.

کلاسی که دانشی از نحوه وهله سازی وهله‌های خود ندارد، abstract class (کلاس مجرد یا انتزاعی) نامیده می‌شود.
کلاسی که دانش نحوه وهله سازی وهله‌های خود دارد، concrete class نامیده می‌شود.

در پارادایم شیء گرا، مهم‌ترین استفاده از کلاس‌های انتزاعی در مباحث ارث بری مطرح می‌شود.

Roles Versus Classes

قاعده شهودی 2.11
مطمئن باشید انتزاع هایی را که مدل می‌کنید کلاس بوده و نه نقش‌هایی که وهله‌های آنها بازی می‌کنند. (Be sure the abstractions that you model are classes and not simply the roles objects play)
آیا مادر و پدر به عنوان یک کلاس هستند یا نقش‌هایی هستند که وهله‌های کلاس شخص، بازی می‌کند؟ پاسخ این سوال وابسته به دامینی (domain) است که طراح در حال مدل سازی آن می‌باشد. اگر در دامین مورد نظر، مادر و پدر رفتارهای مختلفی دارند، احتمالا باید به عنوان کلاس‌های جدا مدل شوند. اگر رفتارهای یکسانی دارند، در نتیجه نقش‌های مختلفی هستند که وهله‌های کلاس شخص بازی می‌کنند. به عنوان مثال، می‌توان کلاس خانواده را متشکل از وهله‌ای از کلاس پدر، وهله‌ای از کلاس مادر و مجموعه‌ای از وهله‌های کلاس فرزند در نظر گرفت. در مقابل ممکن است کلاس خانواده را متشکل از وهله‌ای از کلاس شخص به عنوان پدر، وهله‌ای از کلاس شخص به عنوان مادر و آرایه‌ای از وهله‌های شخص به عنوان فرزندان، مدل کنید. قرار گرفتن در وضیعتی که هر نقش، بخشی از رفتاری‌های شخص را مورد استفاده قرار می‌دهد، کافی نیست و باید مطمئن شوید که رفتار‌ها واقعا متفاوت می‌باشند. همچنین باید به یاد داشته باشید که زمانیکه وهله‌ای از بخشی از رفتارهای کلاس خود استفاده می‌کند، نیز مشکلی وجود ندارد و لازم نیست کلاس‌های دیگری را به خاطر این موضوع در طراحی خود در نظر بگیرید.

شکل 2.9 Two views of a family   

برخی از طراحان به این شکل تست می‌کنند که اگر عضوی از واسط عمومی را نمی‌توان برای نقش مورد نظر  مورد استفاده قرار داد، این موضوع نشان از این دارد که باید برای نقش مورد نظر در طراحی خود کلاس جداگانه‌ای را در نظر داشته باشند. اگر هم عضو مذکور قابل استفاده نباشد، کلاس یکسانی برای نقش‌های مختلف استفاده خواهد شد. به عنوان مثال، اگر عملیات ()go_into_labor جزء عملیاتی می‌باشد که مادر انجام می‌دهد، در حالیکه پدر چنین عملیاتی را نمی‌تواند انجام دهد، در این حالت نیز لازم است مادر به عنوان کلاس جداگانه‌ای در نظر گرفته شود. اگر در دامین دیگری، عوض کردن پوشاک را  تنها مادر انجام می‌دهد، در این حالت مادر نقشی از کلاس شخص می‌باشد، چرا که پدر هم توانایی انجام این عملیات را دارد.

قواعد شهودی فصل دوم

قاعده شهودی 2.1 
همه داده‌ها باید در داخل کلاس خود پنهان شده باشند. (All data should be hidden within its class) 
قاعده شهودی 2.2
استفاده کنندگان از کلاس باید به واسط عمومی آن وابسته باشند، اما یک کلاس نباید به استفاده کنندگان خود، وابسته باشد. (Users of a class must be dependent on its public interface, but a class should not be dependent on its users)
قاعده شهودی 2.3
تعداد پیغام‌های موجود در قرارداد یک کلاس را کمینه سازید. (Minimize the number of messages in the protocol of a class) 
قاعده شهودی 2.4
پیاده سازی یک واسط عمومی یکسان کمینه برای همه کلاس‌ها  (Implement a minimal public interface that all classes understand [e.g., operations such as copy (deep versus shallow), equality testing, pretty printing, parsing from an ASCII description, etc.].) 
قاعده شهودی 2.5 
جزئیات پیاده سازی، مانند توابع خصوصی common-code  ( توابعی که کد مشترک سایر متدهای کلاس را در بدنه خود دارند) را در واسط عمومی یک کلاس قرار ندهید.  (Do not put implementation details such as common-code private functions into the public interface of a class)
قاعده شهودی 2.6 
واسط عمومی کلاس را با اقلامی که یا استفاده کنندگان از کلاس توانایی استفاده از آن را نداشته و یا تمایلی به استفاده از آنها ندارند، آمیخته نکنید.  (Do not clutter the public interface of a class with items that users of that class are not able to use or are not interested in using )
قاعده شهودی 2.7
اتصال و پیوستگی مابین کلاس‌ها باید از نوع Nil یا Export باشد؛ به این معنی که یک کلاس فقط از واسط عمومی کلاس دیگر استفاده کند یا کاری با آن نداشته باشد. (Classes should only exhibit nil or export coupling with other classes, that is, a class should only use operations in the public interface of another class or have nothing to do with that class.)
قاعده شهودی 2.8 
یک کلاس باید یک و تنها یک Key Abstraction را تسخیر نماید. (A class should capture one and only one key abstraction) 
قاعده شهودی 2.9 
داده و رفتار مرتبط را در یک جا (کلاس) نگه دارید. (Keep related data and behavior in one place)
قاعده شهودی 2.10 
اطلاعات نامرتبط به هم را در کلاس‌های جدا از هم قرار دهید. ((Spin off nonrelated information into another class (i.e., noncommunicating behavior)
قاعده شهودی 2.11
مطمئن باشید انتزاع هایی را که مدل می‌کنید کلاس بوده و نه نقش‌هایی که وهله‌های آنها بازی می‌کنند. (Be sure the abstractions that you model are classes and not simply the roles objects play)  
بازخوردهای پروژه‌ها
NetSqlAzMan
NetSqlAzMan is the .NET Sql Authorization Manager short form and is an applicative authorization manager, that is, given an application user, what this user is authorized to do within that application.

 is for all  developers that need to manage loosely-coupled applicative authorizations, that is, weakly coupled with source code, in a light and fast way having all these authorizations in a relational database such as  (2000/MSDE/2005/2008/2012/Express/Compact).  
  • NetSqlAzMan allows you to change User Authorizations without recompile your application ! 
  • NetSqlAzMan supports AOP (Aspect Oriented Programming 
نظرات مطالب
کنترل DatePicker شمسی مخصوص Silverlight 4
با تشکر از جواب سریعتون
کامپوننت رو آوردم و استفاده میکنم ولی موقع اجرای برنامه وقتی stop می‌کنم و می‌خوام به محیط VS 2010 برگردم 2 تاwarning  میده و فرم رو در حالت design نشون نمیده

  1- [A]WpfPersianDatePicker.Views.PDatePicker cannot be cast to [B]WpfPersianDatePicker.Views.PDatePicker. Type A originates from 'WpfPersianDatePicker, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e5d899545a6585ee' in the context 'LoadNeither' at location 'C:\Documents and Settings\HV\Local Settings\Application Data\Microsoft\VisualStudio\10.0\ProjectAssemblies\zgrq7cfx01\WpfPersianDatePicker.DLL'. Type B originates from 'WpfPersianDatePicker, Version=1.1.0.0, Culture=neutral, PublicKeyToken=e5d899545a6585ee' in the context 'Default' at location 'C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\WpfPersianDatePicker.dll'
2-
The variable 'UserControl11' is either undeclared or was never assigned. 
فکر می‌کنم خطای دوم همونیه که شما راهنمایی فرمودین ولی من نتونستم جاشو پیدا کنم
یه سوال دیگه من دارم تاریخ رو از پایگاه می‌خونم می‌تونم تو این کامپوننت موقع لود شدن صفحه بنویسمش مثل dateTimepicker معمولی؟
اشتراک‌ها
مفهوم زبان مشترک در DDD

Account

A bank account allows us to send and receive money and has its unique number. Anytime we tell about an account in a bank, an account is always a bank account. In the other hand, an account in an information system is used to authorize a user. We have the term "account" meaning something absolutely different in two different domains. Domain has an impact on what we imagine when someone says a concrete term. So we have to learn and specify domain terms first.

Price

Let's speak about e-shop domain. What is a price? For us, as customers, it is how much we pay. A manager can think about price as an amount that his company pays to the supplier. For an accountant, a price is just a number. And e-shop programmer is now confused.

Language is crucial because customers and experts are telling their stories in their language. But it is also natural language, inaccurate, ambiguous, context-aware. And as we can see, language can be tricky even within one domain. 


مفهوم زبان مشترک در DDD
اشتراک‌ها
Redis 6.0.0 GA منتشر شد

The next major release of the popular data structure server is here. Redis is at the heart of so many data systems nowadays that any major release is big news but 6.0 packs in a lot of new bits and pieces that make it more robust and capable of modern workloads, including:
- Access Control Lists (ACL) for limiting what certain clients can do.
- Diskless replication on replicas.
- Threaded I/O (but Redis itself remains primarily single threaded).
- SSL/TLS support.
- A new client-server protocol, RESP3.
 

Redis 6.0.0 GA منتشر شد
اشتراک‌ها
Visual Studio 2019 version 16.11.4 منتشر شد
حجم تقریبی آپدیت از نسخه قبلی (16.11.3) حدود 1.11G میشه.
  • Windows 11 SDK support.
  • Adds Xcode 13.0 support.
  • Add AMD64 math functions to ARM64X CRT.
  • Updates to the ARM64 and ARM64EC interfaces between the binary and the POGO instrumentation runtime.
  • Fixed several problems with IntelliSense responsiveness and correctness affecting C++20 concepts, ranges, and abbreviated function templates.
  • Fixed a false positive in local lifetime checks.
  • Corrected an issue where arrays allocated with a constant of size > 32bits could allocate less memory than requested.
  • Ensures that ATL string initialization occurs during static variable initialization, in the default AppDomain.
  • Fixed a bug in C++ Concurrency::parallel_for_each that was crashing the calling process due to integer overflow.
  • Fixed a bug in the STL's iterator debugging machinery that could cause crashes in multithreaded programs using STL containers.
  • We have fixed a fatal internal compiler error caused by unnamed structs whose fields are referenced from SAL annotations.
  • Fixes a rare crash when analyzing templated code that uses __uuidof.
  • Fixed an issue that caused C++ static analysis results to sometimes not display correctly in the FixIt action.
  • Fixed opening .uitest extension files in Coded UI project
  • Fire component change events for non-component objects also in WinForms .NET designer
  • Fix for crash on deleting ContextMenuStrip control in Windows Forms .NET designer.
  • Guard against crashes when the Windows Forms designer reloads when dragging.
  • Fix for intermittent VS crash while interacting with WinForms .NET designer during solution or project rebuild.
  • Fixed a bug causing .NET 5 projects to be reported as out of date when they should have been up to date, causing slower builds.
  • Automatically disable asset-indexing for large scale Unity projects.
  • This release fixes an issue with deploying certain Windows Application Packaging projects where deployment is unnecessarily copying unmodified files. 
Visual Studio 2019 version 16.11.4 منتشر شد
اشتراک‌ها
Aurelia-Toolbelt مجموعه کامپوننتی بر اساس Bootstrap 4 برای Aurelia

Aurelia is one of the best frameworks that we have ever seen in terms of software design, hence, we decided to write a bunch of tools for its developers to pave the way for further usage.

aurelia-toolbelt is that, in which we tried to gather the best libraries in Javascript world together in aurelia fashion. Writing custom-elements, value-converters, and so on. We tried not to invent the wheel, so most of the work is a wrapper, or bridge( am not sure whether the way that we coded can be called bridge or not), around other libraries.

  • Its is utterly important for us to provide a link as a reference to the libraries used, or inspired from, so that other developers can visit their product and decide on their own to use which, besides it's one way that we can respect the time and effort of those programmers.

  • All libraries used in aurelia-toolbelt are open-source and free of charge; most of which are  MIT , however we will provide definition whenever it differs. 

GitHub aurelia-toolbelt

NPM aurelia-toolbelt

Twitter aureliatoolbelt

Aurelia-Toolbelt مجموعه کامپوننتی بر اساس Bootstrap 4 برای Aurelia
اشتراک‌ها
NET 5.0 Preview 5. منتشر شد

we’re about half-way through the release now. Most of the features are now included, but there are still many changes that we expect in the next few previews to complete experiences and round off rough edges that still exist. Take care. 

NET 5.0 Preview 5. منتشر شد