The following are axioms for what I have defined as a best-of-breed approach Ive discovered on my own… I wanted to write a rules based guide for a development approach to application or web deployed solutions driven by C# or PHP OOP ::
classes are encapsulations
you design methods -as business rules - to manipulate instances of classes
each instance of the class ‘instantiated’ is an object
identify static member variables also known as class variables
– these belng to the class not each object - like class ‘globals’ in a sense
you can also declare static methods which can only manipulate static data…
1) Define All Objects::
Object-oriented software analysis and design are preoccupied with the discovery of classes and the relationships they have to each other.
(Nouns,Verbs, Adjectives&Adverbs)
Some objects can be identified
Nouns::
USD,Yen,Pound Dollar Amount,Currency Value
ActionOperations / Verbs are Methods()::
Deposit, Transact, Charge/Send Money
FirstFile(), NextFile(), LastFile, PreviousFile()
public string [] GetFiles()
{
dirs=System.IO.Directory.GetFiles(”c:\\”);
return dirs;
}
public string GetCurrentFile()
{
return dirs(bookmark);
}
public void NextFile()
{
bookmark++;
}
public static BudgetDirectory
operator
++ (BudgetDirectory bd)bd.NextFile();
return db;
cool short circuiting huh !
some verbs can also be Events::
as a Button_Click_Event, or a
Key_Press_Event of a Textbox or
load event of a Form…
next assign a Delegate for event handlers =>
call the System.EventHandler delegate in the
[Windows Form Design generated code] “wiring”
first you must build-out each method then wire events to these methods with delegates…
Adverbs / Operation Conditions (All methods) ::
Block, Refund, Cancel a [Deposit]
Adjectives::
Clearing, Processing[Deposit]
2) Identify & Define all Exceptions::
Harvest all “But ifs & When it is” from the Client
i.e. a negative number in Accounting must be red
then::.
Model & Develop a Class.cs file for EVERY
rules based exception you’ll need to handle
and::.
identify which exemptions youll have to custom define
3) Identify & Define all Operations::
Harvest all “When Operations” from the Client
i.e. Display new deposit of money from my account
public ArrayList NewDeposits
{
get
{
return newDeposits;
}
}
then::.
Model & Develop a Class.cs file for EVERY
rules based Business Action you’ll need to process
this begins to “wrangle-in” all [No3 class object] actions
i.e. Depositing money into my account cannot be negative Dollars
4) Identify every UI Event::
you’ll probably have a button*_Click statement driving each [No3 class object]
i.e. objectify EVERY SQL Statement and design a stored procedure for each
5) Identify each UI Form:: for each button*_Event
6) Model all Conditionals::
Weigh every newly defined [No3 class object]
against
every [No2s class object]
for points of implementation and strategic interlinking
then::.
sculpt an if statement for each [No2 class object]
throw ALL new argument(s) for each [No3 class object]
Design namespacing and make any neccesary aiases…
i.e.
using Widgets = MyCompany.CompanyWidgets.WidgetModelForApplication;
is now::
Widgets.
7) Establish a Plan for Garbage Collection (GC)::
you should have a POA for each form.The .NET GC uses generations to help optimize the collection process and free up resources. Generation 0 contains recently created, frequently accessed objects. Generations 1 and 2, which hold larger and less frequently accessed objects, are not collected as often as Generation 0. The GC will sweep through Generation 0 rather often and free up resources there, but when doing the sweep of Generation 0 it ignores Generations 1 and 2. This means that any objects you have that are using large, expensive resources, such as file and operating system resources or network and database connections, could adversely impact your application’s performance by holding on to precious system resources longer than needed.
- One way to improve performance is to consider your object designs and, if you have resources being held by large, infrequently used objects, take steps to release them sooner than later.
- One way to do this is to implement a Dispose() method on all objects that consume expensive resources that may not be collected and freed as part of Generation 0.
- heres a Great walk down “memory” lane
8) Optimizing CodeBehind ::
When you construct things remember you must
a ) declare new instance,
b ) assign attributes
c ) wire it for events and map it to what it affects
d ) add code in the nested method as needed to handle what you are wanting it to do.
performance speed in efficient code is EVERYTHING ! Sometimes I struggle for hours to earn another microsecond on a callback to a large datagrid…
It can make all the difference using a decimal than a double int.
- The first thing you need to understand and never forget is that you won’t go very far if you try to work against the JIT compiler.
- Carefully choose using per-method (JIT) vs method pre-compilation (NGEN) which could lead to a performance increase only when you want to reduce the startup time of your application.
- You should consider whether you should use threading (no more than 1 at a time / multi-threading decreases performance) and only use it if it is truly required.
- Once you know whether you actually need threads, the next decision is whether you should manage the threading or allow the .NET CLR to handle it. As with the JIT compiler, thread management under .NET is optimized rather well.
- The key to achieving maximum performance with threading is to recycle threads. Threads are objects, and their instantiation is costly. This is clearly an area where understanding the science of threading and the art of performance is critical.
- Throwing exceptions is another area that can lead to performance degradation. It is important that you consider the use of exceptions and how they affect your application. Please understand that I am not advocating that you do not use “Try…Catch” blocks in your code, but rather that you understand when exceptions are thrown and how they impact your code. Exceptions, by sheer nature, are expensive operations.
- Use the .NET performance counters to see how many exceptions your application is throwing.
- Also, be wary of integration with unmanaged code in which things like COM objects and System API calls can throw exceptions that can impact performance.
- The ability to achieve better performance is often a result of how you balance the work to be performed by the client and the server.
- You will dramatically increase performance if you can package the data you need to send across the wire while minimizing the number of method calls.
- Go Native
The use of native data types will help minimize the expense associated with marshaling. You incur expense, and thereby degrade performance, when you create situations where data translation is required. For instance, moving data from ASCII to Unicode or in some cases from XML to another format can create expensive marshaling scenarios. While planning your application you can drastically improve performance if your development team agrees on how you will manage data between your client and server objects.
- Use the Right GC
The .NET CLR has two garbage collectors, the workstation version (mscorwks.dll) and the server version (mscorsvr.dll). The server version is optimized for throughput and is also more aggressive about collections, so it minimizes memory fragmentation, takes advantage of multiple processors, and can also support multiple heaps. The workstation version minimizes latency and can also recognize multiple processors, but is best used in a single-processor workstation scenario. In some cases you may be running your client objects on a multiprocessor workstation communicating with objects on a server. In this case you can force the workstation to use the server version of the GC so that you can reap the benefits of the server version even though you are running on a workstation.
- Security
The last area we will examine is the impact security has on performance. I left it for last because I honestly feel that security is an area where you need to be very careful that your quest for speed doesn’t leave you exposed.
Security affects performance; .NET security is optimized and has several techniques it uses to minimize impact on performance, but there are situations where a security check on a method will cause a walk of the stack. One thing to do is minimize the stack walk. Yes, .NET does this on its own by using declarative security instead of imperative. When PermitOnly, Deny, or Assert are declared, you can avoid the stack walk. Another option is to do as many of your security checks at link time instead of runtime, using “LinkDemand” to do code checks, as opposed to identity checks.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Note to other developers :
Please consider this loose and mailable to evolve with your feedback. I think it is an essential tool for problem solving and want to continue to refine for the benefit of all…