samedi 25 juin 2016

Pattern for Multi User ASP.NET with SQL/LINQ

I have a SQL+ASP.NET situation for which I suspect there might exists a design pattern.

I have a site where users can register and then enter their own data. The users can only see their own data and never anything else.

My question is: Is there a way to somehow simplify this process. All SQL commands clearly need to be filtered based on the user ID, and ASP Web Forms doesn't really allow this in a simple way. Is there a way to maybe produce LINQ objects or something similar that can automatically extend every SQL command sent to the SQL Server with a User ID parameter?

Using closures or the underscore convention for private members

Douglas Crackford and many others suggest using closures for private members as follows:

function Container(param) {

    function dec() {
        if (secret > 0) {
            secret -= 1;
            return true;
        } else {
            return false;
        }
    }

    this.member = param;
    var secret = 3;
    var that = this;
}

The upside of this is that these members are not accessible outside the constructor function, but the downside is that it's not possible to use the private members in the prototype. So you end up putting everything that uses the private members in the constructor, which is not good for memory purposes.

Some others recommend using underscores when naming the private members:

function Container(param) {
    this.member = param;
    this._secret = 3;
}

Container.prototype.dec = function {
    if (this.secret > 0) {
        this.secret -= 1;
        return true;
    } else {
        return false;
    }
}

The downside of this is that those members are easily accessible publicly, and the only thing stopping people is the convention.

My questions are:

  1. When do you decide to use one over the other?
  2. Is one way preferred more commonly than the other?
  3. What are some famous libraries that use one of these methods?
  4. Is there a better method than these two?

Unit testing Application design, Design Pattern, Best Practices

In general mostly I write unit test for testing the functionality of the application/methods. In my recent reading, I've come across concept of Unit testing the "Loose Coupling" of the application components. I noticed a Unit test written to check the reference of unexpected assemblies (e.g Presentation layer directly referring DataAccess Classes instead of Business Logic classes), This unit test will immediately fail if it encounters the unexpected references that breaks "loosely coupled" design.

I like this concept of writing unit testing to test the best practice/design of the application. Just want to see if there are any pointers/resources which will help us write Unit test to test the application design/architecture.

Please share if you know anything more about this area.

This is the sample code.

[Fact]
public void SutShouldNotReferenceSqlDataAccess()
{
// Fixture setup
Type sutRepresentative = typeof(HomeController);
var unwanted = "Ploeh.Samples.Commerce.Data.Sql";
// Exercise system
var references =
sutRepresentative.Assembly
.GetReferencedAssemblies();
// Verify outcome
Assert.False(
references.Any(a => a.Name == unwanted),
string.Format(
"{0} should not be referenced by SUT",
unwanted));
// Teardown
}

What kind of javascript design pattern was used in facebook website?

I've trying to study with Javascript design patterns to improve my practice but I simply confused with all kind of those patterns special I found a style which was used in facebook script (study) it simple and may be easy to use if I've much understand about those design patterns so I would like to ask all expert here about the kind of patterns that facebook used with the Javascript library (react js)as below code

__d('StaticUFI.react',
    ['getElementPosition', 'getElementRect', 'getUnboundedScrollPosition',
    'shallowEqual', 'throttle'],
    function a(b, c, d, e, f, g, h, i) {
    'use strict';
    var j = c('UFIConstants').UFIFeedbackSourceType,
        k = c('UFIConstants').UFIStatus,
        l = c('React').PropTypes,
        m = c('React').createElement('div', {className: "UFICommentsLoadingSpinnerContainer _48pi UFIRow"},
            c('React').createElement(c('XUISpinner.react'), {size: 'large'})),
        n = c('React').createElement('div', {
            className: "_xtv",
            role: 'presentation'
        }, c('React').createElement('i', null)), o = c('React').createClass({
            displayName: 'StaticUFI',
            contextTypes: {dispatch: l.func},
            getInitialState: function () {
                var p = this.props.focusReply;
                return {focusReply: p, viewerHasClickedCommentComposer: false, viewerHasClickedSeeMore: false};
            },
            getDefaultProps: function () {
                return {
                    commentIDToFocusOnMount: null,
                    focusReply: null,
                    canReplyMap: {},
                    isActiveLoading: {},
                    repliesExpandedMap: {},
                    hasPagedToplevel: false,
                    viewerHasInteractedWithComments: false,
                    loadingSpamIDs: {}
                };
            },
            componentDidMount: function () {
                c('Arbiter').inform('UFI/displayDone-' + this.props.contextArgs.instanceid);
                if (this.props.feedback.isqanda && this.props.feedback.infinitescroll) {
                    var p = c('throttle')(this.loadMoreComments, 20);
                    this._scrollEventListener = c('Event').listen(window, 'scroll', p);
                    this._resizeEventListener = c('Event').listen(window, 'resize', p);
                }
                if (c('BlueBar').hasFixedBlueBar())this.setState({oldBoundingClientRect: c('getElementRect')(c('ReactDOM').findDOMNode(this))});
                this._resolveFocus();
            },
            loadMoreComments: function () {
                if (this.isMounted() && this.refs.topLevelBottomPager && !(this.props.contextArgs.ftentidentifier in this.props.isActiveLoading)) {
                    var p = c('ReactDOM').findDOMNode(this.refs.topLevelBottomPager),
                        q = c('getUnboundedScrollPosition')(window).y,
                        r = q + document.documentElement.clientHeight + c('UFIConstants').infiniteScrollRangeForQANDAPermalinks;
                    if (p.offsetHeight && p.offsetTop < r)this.refs.topLevelBottomPager.props.onPagerClick();
                }
            }
        });
    f.exports = o;
}, null);

Why Service Locator is referred as AntiPattern?

I read from many Articles that Service Locator is Antipattern, but I couldnt clearly understand why it is called out as AntiPattern. I appreciate any examples pointers over this.

Design patterns in Programming Languages and design patterns in Cloud computing

I have a confusion what are the exactly design patterns in cloud computing are? what exactly is the difference between these two design patters and programming language design patterns. I know design patterns in Programming languages are used for the problems Which are reoccurring again and again. but what is the purpose of design patterns in cloud computing. Some companies are providing services for hardware, web application development. can anyone explain

what actually is the purpose of design patterns coding techniques in cloud computing..

vendredi 24 juin 2016

Mark modified object and unmark it from outside

This is kind of a follow up of this question of my own.

I have a Tournament class which has a List<Event>, the categories of the event. You can instantiate a tournament and then make changes on its events:

Event event = new Event(...);
Tournament tournament = new Tournament(..., new ArrayList<>(Arrays.asList(event)));
event.setProperty(property);

However, the Tournament class is part of a resolution process that calculates all the possible schedules it has, one by one. The model the solver class uses to compute the schedule is based on the state of the tournament (and its events) in the moment the resolution process begins (calling tournament.solve()).

We can retrieve subsequent schedules (the next solution) by invoking tournament.nextSchedules(). And here's the problem. As I said the solver holds the configuration of the tournament from the instant that solve() was called. If now we start changing properties of any event (which is allowed), the current model of the tournament, the instance, will be no longer consistent with the model the solver holds. This has to be managed, otherwise I will be getting wrong schedules, or even errors.

Now to the point: as I was suggested in the previous question, I tried implementing a solution to track any modifications made in the events. For that I made the Event class extend Observable and setChanged() is being called from every method that modifies properties (or those relevant to the model in the solver anyway). Here's a sample:

public Event extends Observable implements Validable {
    public void setProperty(Property property) {
        //...
        setChanged();
    }
}

Having done that, now I need a way to reset the changes flag on the observable event when they're considered in a final form. And when does this happen? Well, whenever tournament.solve() is called. When trying to solve the problem and retrieve the schedules, the tournament (therefore, its events) are in a consistent state. The problem is that to clear the changed flag on a event, I need to use the clearChanged() method and it is not public, which kind of makes sense because it should be up to the observable object to determine if it's changed or not anymore. In my scenario though, it's actually up to a different class, the Tournament class, to say if an event has changed or not.

I could very well define a public method in the Event class wrapping the clearChanged() method, but this would break the whole point of the Observable interface as I understand it.

What changes should I make in order to allow a Tournament to notify its events that they have no longer changed?