Skip to content

Commit 1797f38

Browse files
committed
update
Refactor factories
1 parent e35aa21 commit 1797f38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+236
-230
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
* PureMVC Standard Framework for C# - Copyright © 2017 [Saad Shams](http://saad.io)
2-
* PureMVC - Copyright © 2017 [Futurescale, Inc](http://futurescale.com).
1+
* PureMVC Standard Framework for C# - Copyright © 2020 [Saad Shams](http://saad.io)
2+
* PureMVC - Copyright © 2020 [Futurescale, Inc](http://futurescale.com).
33
* All rights reserved.
44

55
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

PureMVC/Core/Controller.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -58,7 +58,7 @@ public class Controller: IController
5858
/// <exception cref="System.Exception">Thrown if Singleton instance has already been constructed</exception>
5959
public Controller()
6060
{
61-
if (instance != null) throw new Exception(Singleton_MSG);
61+
if (instance != null) throw new Exception(SingletonMsg);
6262
instance = this;
6363
commandMap = new ConcurrentDictionary<string, Func<ICommand>>();
6464
InitializeController();
@@ -92,13 +92,13 @@ protected virtual void InitializeController()
9292
/// <summary>
9393
/// <c>Controller</c> Singleton Factory method.
9494
/// </summary>
95-
/// <param name="controllerFunc">the <c>FuncDelegate</c> of the <c>IController</c></param>
95+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IController</c></param>
9696
/// <returns>the Singleton instance of <c>Controller</c></returns>
97-
public static IController GetInstance(Func<IController> controllerFunc)
97+
public static IController GetInstance(Func<IController> factory)
9898
{
9999
if (instance == null)
100100
{
101-
instance = controllerFunc();
101+
instance = factory();
102102
}
103103
return instance;
104104
}
@@ -110,9 +110,9 @@ public static IController GetInstance(Func<IController> controllerFunc)
110110
/// <param name="notification">note an <c>INotification</c></param>
111111
public virtual void ExecuteCommand(INotification notification)
112112
{
113-
if (commandMap.TryGetValue(notification.Name, out Func<ICommand> commandFunc))
113+
if (commandMap.TryGetValue(notification.Name, out var factory))
114114
{
115-
ICommand commandInstance = commandFunc();
115+
var commandInstance = factory();
116116
commandInstance.Execute(notification);
117117
}
118118
}
@@ -129,18 +129,18 @@ public virtual void ExecuteCommand(INotification notification)
129129
/// </para>
130130
/// <para>
131131
/// The Observer for the new ICommand is only created if this the
132-
/// first time an ICommand has been regisered for this Notification name.
132+
/// first time an ICommand has been registered for this Notification name.
133133
/// </para>
134134
/// </remarks>
135135
/// <param name="notificationName">the name of the <c>INotification</c></param>
136-
/// <param name="commandFunc">the <c>Func Delegate</c> of the <c>ICommand</c></param>
137-
public virtual void RegisterCommand(string notificationName, Func<ICommand> commandFunc)
136+
/// <param name="factory">the <c>Func Delegate</c> of the <c>ICommand</c></param>
137+
public virtual void RegisterCommand(string notificationName, Func<ICommand> factory)
138138
{
139-
if (commandMap.TryGetValue(notificationName, out Func<ICommand> _) == false)
139+
if (commandMap.TryGetValue(notificationName, out _) == false)
140140
{
141141
view.RegisterObserver(notificationName, new Observer(ExecuteCommand, this));
142142
}
143-
commandMap[notificationName] = commandFunc;
143+
commandMap[notificationName] = factory;
144144
}
145145

146146
/// <summary>
@@ -149,7 +149,7 @@ public virtual void RegisterCommand(string notificationName, Func<ICommand> comm
149149
/// <param name="notificationName">the name of the <c>INotification</c> to remove the <c>ICommand</c> mapping for</param>
150150
public virtual void RemoveCommand(string notificationName)
151151
{
152-
if (commandMap.TryRemove(notificationName, out Func<ICommand> _))
152+
if (commandMap.TryRemove(notificationName, out _))
153153
{
154154
view.RemoveObserver(notificationName, this);
155155
}
@@ -175,6 +175,6 @@ public virtual bool HasCommand(string notificationName)
175175
protected static IController instance;
176176

177177
/// <summary>Message Constants</summary>
178-
protected const string Singleton_MSG = "Controller Singleton already constructed!";
178+
protected const string SingletonMsg = "Controller Singleton already constructed!";
179179
}
180180
}

PureMVC/Core/Model.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -46,7 +46,7 @@ public class Model: IModel
4646
/// <exception cref="System.Exception">Thrown if instance for this Singleton key has already been constructed</exception>
4747
public Model()
4848
{
49-
if (instance != null) throw new Exception(Singleton_MSG);
49+
if (instance != null) throw new Exception(SingletonMsg);
5050
instance = this;
5151
proxyMap = new ConcurrentDictionary<string, IProxy>();
5252
InitializeModel();
@@ -70,13 +70,13 @@ protected virtual void InitializeModel()
7070
/// <summary>
7171
/// <c>Model</c> Singleton Factory method.
7272
/// </summary>
73-
/// <param name="modelFunc">the <c>FuncDelegate</c> of the <c>IModel</c></param>
73+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IModel</c></param>
7474
/// <returns>the instance for this Singleton key </returns>
75-
public static IModel GetInstance(Func<IModel> modelFunc)
75+
public static IModel GetInstance(Func<IModel> factory)
7676
{
7777
if (instance == null)
7878
{
79-
instance = modelFunc();
79+
instance = factory();
8080
}
8181
return instance;
8282
}
@@ -98,7 +98,7 @@ public virtual void RegisterProxy(IProxy proxy)
9898
/// <returns>the <c>IProxy</c> instance previously registered with the given <c>proxyName</c>.</returns>
9999
public virtual IProxy RetrieveProxy(string proxyName)
100100
{
101-
return proxyMap.TryGetValue(proxyName, out IProxy proxy) ? proxy : null;
101+
return proxyMap.TryGetValue(proxyName, out var proxy) ? proxy : null;
102102
}
103103

104104
/// <summary>
@@ -108,7 +108,7 @@ public virtual IProxy RetrieveProxy(string proxyName)
108108
/// <returns>the <c>IProxy</c> that was removed from the <c>Model</c></returns>
109109
public virtual IProxy RemoveProxy(string proxyName)
110110
{
111-
if (proxyMap.TryRemove(proxyName, out IProxy proxy))
111+
if (proxyMap.TryRemove(proxyName, out var proxy))
112112
{
113113
proxy.OnRemove();
114114
}
@@ -132,6 +132,6 @@ public virtual bool HasProxy(string proxyName)
132132
protected static IModel instance;
133133

134134
/// <summary>Message Constants</summary>
135-
protected const string Singleton_MSG = "Model Singleton already constructed!";
135+
protected const string SingletonMsg = "Model Singleton already constructed!";
136136
}
137137
}

PureMVC/Core/View.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -46,7 +46,7 @@ public class View: IView
4646
/// <exception cref="System.Exception">Thrown if Singleton instance has already been constructed</exception>
4747
public View()
4848
{
49-
if (instance != null) throw new Exception(Singleton_MSG);
49+
if (instance != null) throw new Exception(SingletonMsg);
5050
instance = this;
5151
mediatorMap = new ConcurrentDictionary<string, IMediator>();
5252
observerMap = new ConcurrentDictionary<string, IList<IObserver>>();
@@ -71,13 +71,13 @@ protected virtual void InitializeView()
7171
/// <summary>
7272
/// <c>View</c> Singleton Factory method.
7373
/// </summary>
74-
/// <param name="viewFunc">the <c>FuncDelegate</c> of the <c>IView</c></param>
74+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IView</c></param>
7575
/// <returns>the instance for this Singleton key </returns>
76-
public static IView GetInstance(Func<IView> viewFunc)
76+
public static IView GetInstance(Func<IView> factory)
7777
{
7878
if (instance == null)
7979
{
80-
instance = viewFunc();
80+
instance = factory();
8181
}
8282
return instance;
8383
}
@@ -90,7 +90,7 @@ public static IView GetInstance(Func<IView> viewFunc)
9090
/// <param name="observer">the <c>IObserver</c> to register</param>
9191
public virtual void RegisterObserver(string notificationName, IObserver observer)
9292
{
93-
if (observerMap.TryGetValue(notificationName, out IList<IObserver> observers))
93+
if (observerMap.TryGetValue(notificationName, out var observers))
9494
{
9595
observers.Add(observer);
9696
}
@@ -114,14 +114,14 @@ public virtual void RegisterObserver(string notificationName, IObserver observer
114114
public virtual void NotifyObservers(INotification notification)
115115
{
116116
// Get a reference to the observers list for this notification name
117-
if (observerMap.TryGetValue(notification.Name, out IList<IObserver> observers_ref))
117+
if (observerMap.TryGetValue(notification.Name, out var observersRef))
118118
{
119119
// Copy observers from reference array to working array,
120120
// since the reference array may change during the notification loop
121-
var observers = new List<IObserver>(observers_ref);
121+
var observers = new List<IObserver>(observersRef);
122122

123123
// Notify Observers from the working array
124-
foreach (IObserver observer in observers)
124+
foreach (var observer in observers)
125125
{
126126
observer.NotifyObserver(notification);
127127
}
@@ -136,10 +136,10 @@ public virtual void NotifyObservers(INotification notification)
136136
public virtual void RemoveObserver(string notificationName, object notifyContext)
137137
{
138138
// the observer list for the notification under inspection
139-
if (observerMap.TryGetValue(notificationName, out IList<IObserver> observers))
139+
if (observerMap.TryGetValue(notificationName, out var observers))
140140
{
141141
// find the observer for the notifyContext
142-
for (int i = 0; i < observers.Count; i++)
142+
for (var i = 0; i < observers.Count; i++)
143143
{
144144
if (observers[i].CompareNotifyContext(notifyContext))
145145
{
@@ -153,7 +153,7 @@ public virtual void RemoveObserver(string notificationName, object notifyContext
153153
// Also, when a Notification's Observer list length falls to
154154
// zero, delete the notification key from the observer map
155155
if (observers.Count == 0)
156-
observerMap.TryRemove(notificationName, out IList<IObserver> _);
156+
observerMap.TryRemove(notificationName, out _);
157157
}
158158
}
159159

@@ -182,18 +182,18 @@ public virtual void RegisterMediator(IMediator mediator)
182182
if(mediatorMap.TryAdd(mediator.MediatorName, mediator))
183183
{
184184
// Get Notification interests, if any.
185-
string[] interests = mediator.ListNotificationInterests();
185+
var interests = mediator.ListNotificationInterests();
186186

187187
// Register Mediator as an observer for each notification of interests
188188
if (interests.Length > 0)
189189
{
190-
// Create Observer referencing this mediator's handlNotification method
190+
// Create Observer referencing this mediator's handleNotification method
191191
IObserver observer = new Observer(mediator.HandleNotification, mediator);
192192

193193
// Register Mediator as Observer for its list of Notification interests
194-
for (int i = 0; i < interests.Length; i++)
194+
foreach (var interest in interests)
195195
{
196-
RegisterObserver(interests[i], observer);
196+
RegisterObserver(interest, observer);
197197
}
198198
}
199199
// alert the mediator that it has been registered
@@ -208,7 +208,7 @@ public virtual void RegisterMediator(IMediator mediator)
208208
/// <returns>the <c>IMediator</c> instance previously registered with the given <c>mediatorName</c>.</returns>
209209
public virtual IMediator RetrieveMediator(string mediatorName)
210210
{
211-
return mediatorMap.TryGetValue(mediatorName, out IMediator mediator) ? mediator : null;
211+
return mediatorMap.TryGetValue(mediatorName, out var mediator) ? mediator : null;
212212
}
213213

214214
/// <summary>
@@ -219,15 +219,15 @@ public virtual IMediator RetrieveMediator(string mediatorName)
219219
public virtual IMediator RemoveMediator(string mediatorName)
220220
{
221221
// Retrieve the named mediator
222-
if (mediatorMap.TryRemove(mediatorName, out IMediator mediator))
222+
if (mediatorMap.TryRemove(mediatorName, out var mediator))
223223
{
224224
// for every notification this mediator is interested in...
225-
string[] interests = mediator.ListNotificationInterests();
226-
for (int i = 0; i < interests.Length; i++)
225+
var interests = mediator.ListNotificationInterests();
226+
foreach (var interest in interests)
227227
{
228228
// remove the observer linking the mediator
229-
// to the notification interest
230-
RemoveObserver(interests[i], mediator);
229+
// to the notification interest
230+
RemoveObserver(interest, mediator);
231231
}
232232

233233
// remove the mediator from the map
@@ -256,6 +256,6 @@ public virtual bool HasMediator(string mediatorName)
256256
protected static IView instance;
257257

258258
/// <summary>Message Constants</summary>
259-
protected const string Singleton_MSG = "View Singleton already constructed!";
259+
protected const string SingletonMsg = "View Singleton already constructed!";
260260
}
261261
}

PureMVC/Interfaces/ICommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -16,7 +16,7 @@ public interface ICommand: INotifier
1616
/// <summary>
1717
/// Execute the <c>ICommand</c>'s logic to handle a given <c>INotification</c>.
1818
/// </summary>
19-
/// <param name="Notification">an <c>INotification</c> to handle.</param>
20-
void Execute(INotification Notification);
19+
/// <param name="notification">an <c>INotification</c> to handle.</param>
20+
void Execute(INotification notification);
2121
}
2222
}

PureMVC/Interfaces/IController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -43,8 +43,8 @@ public interface IController
4343
/// for a particular <c>INotification</c>.
4444
/// </summary>
4545
/// <param name="notificationName">the name of the <c>INotification</c></param>
46-
/// <param name="commandFunc">the FuncDelegate of the <c>ICommand</c></param>
47-
void RegisterCommand(string notificationName, Func<ICommand> commandFunc);
46+
/// <param name="factory">the FuncDelegate of the <c>ICommand</c></param>
47+
void RegisterCommand(string notificationName, Func<ICommand> factory);
4848

4949
/// <summary>
5050
/// Execute the <c>ICommand</c> previously registered as the

PureMVC/Interfaces/IFacade.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -41,7 +41,7 @@ public interface IFacade: INotifier
4141
/// Retrieve a <c>IProxy</c> from the <c>Model</c> by name.
4242
/// </summary>
4343
/// <param name="proxyName">the name of the <c>IProxy</c> instance to be retrieved.</param>
44-
/// <returns>the <c>IProxy</c> previously regisetered by <c>proxyName</c> with the <c>Model</c>.</returns>
44+
/// <returns>the <c>IProxy</c> previously registered by <c>proxyName</c> with the <c>Model</c>.</returns>
4545
IProxy RetrieveProxy(string proxyName);
4646

4747
/// <summary>
@@ -62,8 +62,8 @@ public interface IFacade: INotifier
6262
/// Register an <c>ICommand</c> with the <c>Controller</c>.
6363
/// </summary>
6464
/// <param name="notificationName">the name of the <c>INotification</c> to associate the <c>ICommand</c> with.</param>
65-
/// <param name="commandFunc">a reference to the <c>FuncDelegate</c> of the <c>ICommand</c></param>
66-
void RegisterCommand(string notificationName, Func<ICommand> commandFunc);
65+
/// <param name="factory">a reference to the <c>FuncDelegate</c> of the <c>ICommand</c></param>
66+
void RegisterCommand(string notificationName, Func<ICommand> factory);
6767

6868
/// <summary>
6969
/// Remove a previously registered <c>ICommand</c> to <c>INotification</c> mapping from the Controller.

PureMVC/Interfaces/IMediator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/INotification.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Standard
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

0 commit comments

Comments
 (0)