code-design

AngularJS Best Practice - Factory with multiple methods

て烟熏妆下的殇ゞ 提交于 2019-12-07 13:56:16
问题 I have a factory that serves up three different $http.get methods. angular.module('myApp') .factory('getFactory', function ($http, $q) { return { methodOne: function () { var deferred = $q.defer(); $http.get('path/to/data') .then(function successCallback (data) { deferred.resolve(data); },function errorCallback (response) { console.log(response); }); return deferred.promise; }, methodTwo: function (arg1, arg2) { var deferred = $q.defer(); $http.get('path/to/' + arg1 + '/some/' + arg2 + 'more

Authentication in Jersey

一世执手 提交于 2019-12-07 09:16:21
问题 I want to implement authentication for my Jersey0based server/client REST but I'm not sure how exactly to lay out the code. Basically for every operation I have 2 methods - 1 from the server side, 1 from the client side. I've narrowed down the algorithm - I'm going to use the amazon strategy with HMAC. The question is how to lay out this in the code - should I add the authentication (encryption/decryption code) into every method - both server/client side or should I have one "dispatch" method

AngularJS Best Practice - Factory with multiple methods

早过忘川 提交于 2019-12-06 01:29:24
I have a factory that serves up three different $http.get methods. angular.module('myApp') .factory('getFactory', function ($http, $q) { return { methodOne: function () { var deferred = $q.defer(); $http.get('path/to/data') .then(function successCallback (data) { deferred.resolve(data); },function errorCallback (response) { console.log(response); }); return deferred.promise; }, methodTwo: function (arg1, arg2) { var deferred = $q.defer(); $http.get('path/to/' + arg1 + '/some/' + arg2 + 'more/data') .then(function successCallback (data) { deferred.resolve(data); },function errorCallback

Authentication in Jersey

一曲冷凌霜 提交于 2019-12-05 16:33:56
I want to implement authentication for my Jersey0based server/client REST but I'm not sure how exactly to lay out the code. Basically for every operation I have 2 methods - 1 from the server side, 1 from the client side. I've narrowed down the algorithm - I'm going to use the amazon strategy with HMAC. The question is how to lay out this in the code - should I add the authentication (encryption/decryption code) into every method - both server/client side or should I have one "dispatch" method on both sides which would perform the encryption/decryption and then will transfer execution control

Visitor Pattern for two arguments

天大地大妈咪最大 提交于 2019-12-05 04:12:44
Here is a problem statement: We have interfaces/super classes Student and Teacher Student has two implementations/sub clasees, ScienceStudent and PhysicalEducationStudent Teacher has ScienceTeacher and PhysicalEducationTeacher. We want to implement a method getMeetingPoint(Student s, Teacher t) which returns a place where they meet based on the type of Student and Teacher. For example, if its a ScienceStudent and ScienceTeacher they meet at Lab if PEStudent and PETeacher they meet on the Ground and if its a ScienceStudent and PETeacher or vice versa, they meet at cafeteria We can write a naive

Requiring same module in multiple files

﹥>﹥吖頭↗ 提交于 2019-12-04 18:23:59
问题 I'm using Underscore.js in my project. Almost all files have this line of code: var _ = require('underscore') . The require function is synchronous so the same file is loaded each time it is used. Is this the right thing to do? Doesn't this affect performance? Instead of this, is it okay to define a global variable in the app.js file? _ = require('underscore') I've read that you shouldn't use global variables, but this seems to be a valid use case. 回答1: From the node.js documentation: Modules

Is it expensive to create objects in .Net?

試著忘記壹切 提交于 2019-12-03 16:29:37
问题 I have just refactored a colleague's code that, roughly, looked like this... public class Utility public void AddHistoryEntry(int userID, HistoryType Historytype, int companyID) { // Do something... } public void AddHistoryEntry(int userID, HistoryType historyType, int companyID, string notes) { // Do something... } } To this... public class HistoryEntry { public long UserID { get; private set; } public HistoryType HistoryType { get; private set; } public long CompanyID { get; set; } public

Why isn't there a string.Split(string) overload? [closed]

不羁岁月 提交于 2019-12-01 03:38:59
Are there any valid reasons why there isn't an overload of the String.Split which accepts a delimiter string and a text to be split? string[] Split(string delimiter) which could then be used like string input = "This - is - an - example"; string[] splitted = input.Split(" - "); // results in: // { "This", "is", "an", "example" } I really know, that I can create an extention method easily, but there must be valid reason why this has not been added. Please note, that I am not looking for a solution of how to split a string using a string delimiter, I am rather looking for an explanation, why

C++: How to design a utility class?

大兔子大兔子 提交于 2019-11-30 14:38:27
But I don't know if I should go for static methods, just a header, a class, or something else? What would be best practice? But, I don't want to have an instance of a utility class. I want to add functions like: Uint32 MapRGB (int r, int g, int b); const char* CopyString(const char* char); // etc. You know: utility methods... Don't put them in a class; just make them non-member functions at namespace scope. There's no rule that says every function has to be a member function of some class. One factor is whether to even put them in a class, or just put them as nomembers in a namespace (in Java,

Should you avoid static classes?

自闭症网瘾萝莉.ら 提交于 2019-11-30 13:44:10
问题 are static classes considered bad practice? I read an article about this a couple days ago (can't find it, sorry) which basically said that having static classes (especially those 'helper' classes) are typically a sign of bad code. Is this correct, and if so, for what reasons? 回答1: The abuse of static classes can be considered bad practice. But so can the abuse of any language feature. I make no distinction between a non-static class with only static methods and a static class. They are