vendredi 27 février 2015

Encapsulating business logic that goes beyond validations in MVC


I'm pretty clear business logic goes into Models. But on this question, they refer to business logic as pretty much low level validation (if the user signs up, ask for their e-mail).


What about business logic that goes beyond validation? For example, right now I'm working on a project where the user is able to generate a quotation after a form submission. Once submitted, the application will process several data (that are not related to said form) and create some more database rows. This process involves 3 different model entities, which clearly indicates placing the code for this process inside any of those model entity classes would be "wrong".


Right now I'm using Unit of Work pattern to encapsulate CRUD operations (database and mock for testing), but I have somewhere read about some called Service pattern, that encapsulates said UnitOfWork and possibly processes like described above.


What's the pattern used for this kind of logic?





Math expression in swift repl


I have a code



#!/usr/bin/env xcrun swift
import Foundation

let expn = NSExpression(format:"2+2*2")

println(expn.expressionValueWithObject(nil, context: nil))


How to make so that I introduced the mathematical expression in the console for example



./File.Swift 5 + 6 * pi / 2




Constructor-only subclasses: Is this an anti-pattern?


I was having a discussion with a co-worker, and we ended up having conflicting intuitions about the purpose of subclassing. My intuition is that if a primary function of a subclass is to express a limited range of possible values of its parent, then it probably shouldn't be a subclass. He argued for the opposite intuition: that subclassing represents an object's being more "specific", and therefore a subclass relationship is more appropriate.


To put my intuition more concretely, I think that if I have a subclass that extends a parent class but the only code that subclass overrides is a constructor (yes, I know constructors don't generally "override", bear with me), then what was really needed was a helper method.


For example, consider this somewhat real-life class:



public class DataHelperBuilder
{
public string DatabaseEngine { get; set; }
public string ConnectionString { get; set; }

public DataHelperBuilder(string databaseEngine, string connectionString)
{
DatabaseEngine = databaseEngine;
ConnectionString = connectionString;
}

// Other optional "DataHelper" configuration settings omitted

public DataHelper CreateDataHelper()
{
Type dataHelperType = DatabaseEngineTypeHelper.GetType(DatabaseEngine);
DataHelper dh = (DataHelper)Activator.CreateInstance(dataHelperType);
dh.SetConnectionString(ConnectionString);

// Omitted some code that applies decorators to the returned object
// based on omitted configuration settings

return dh;
}
}


His claim is that it would be entirely appropriate to have a subclass like this:



public class SystemDataHelperBuilder
{
public SystemDataHelperBuilder()
: base(Configuration.GetSystemDatabaseEngine(),
Configuration.GetSystemConnectionString())
{
}
}


So, the question:



  1. Among people who talk about design patterns, which of these intuitions is correct? Is subclassing as described above an anti-pattern?

  2. If it is an anti-pattern, what is its name?


I apologize if this turns out to have been an easily googleable answer; my searches on google mostly returned information about the telescoping constructor anti-pattern and not really what I was looking for.





Are there any limitations to using a MacBook Pro with Bootcamp for windows based development? [on hold]


I'm looking at getting a Macbook Pro as my next dev machine. I intend to install Windows on Bootcamp. I do most of my development work on Windows.


The type of dev work I do and tools I use is as follows...



  • Asp.Net MVC and Web Forms

  • EpiServer

  • WPF

  • PHP

  • NodeJS

  • AngularJs

  • Sql Server

  • MySQL

  • Photoshop/Illustrator

  • GIT

  • iOS objective-c


Are there limitations I may come across with using a Mac with bootcamp, that I wouldn't if I was using a PC?





Weird problem while installing Adobe After Effects CS 4. Help me! [on hold]


I am trying to install the Adobe Creative Suite 4. Every thing works fine except the installation of After Effects and Illustrator. The problem is that I can't even select (check) the After Effects option from the custom install option of the setup. All the check marks are normal except it. But surprisingly when I see the payloads folder where all the files and setups of the software are, I can see all the files required to install After Effects are normally there. Why isn't the setup installing it then? Or at least why cant I check mark the After Effects installing option from the setup? Has anybody experienced such issue? Screen Shot image below. enter image description here





PHP MVC Model with a method to fetch all of the model from database


I have a crazy question, consider I'm developing a blog website, There is two model named Post and Comment, now I wanna add a method to fetch all comments from database, which model should I choose to add this method to? Post or Comment.


Approach 1:



$post= new Post();
$post->setID($id);
$r = $post->loadAllComments();


Approach 2:



$r = Comment::loadAllComments($post_id);




Payment for my work [on hold]


Recently, I was working with a Swedish guy on an indie pixel rpg game (don't bother pointing out that a million of them already exist, i know). We got in contact via a programming site's post a job section, and at the time I started the project, since I wasn't too keen to money, we decided to negotiate that later (he was willing to pay, but i foolishly declined). I worked with him for 6 months, and the game is very nearly in it's alpha stage. Seeing as how the game was so nearly finished, he talked to some guys (in Sweden, the govt apparently has a free consulting service for small business owners), and now he's asking me for the source code. That isn't such a big issue by itself, but apprently he thinks he owns the game 100%. He has been paying the artists and stuff so the assets are owned by him, but definitely not the code - which he apparently assumes he owns. I talked to him yesterdy regarding the same, and he's (after a lot of talking) willing to give me 20% ownership of the game, an upfront payment of 400$ and 20% profit sharing. However, on earlier ocassions, he has already mentioned upto 50% profit sharing, and i'm not sure if 20% ownership and 400$ payment is enough to compensate me for my efforts.


So I'd like to ask you, what do you think about this? Is his offer fair, and should i take it? Or should I ask him to consider some other terms? Failing that, should i leave the project?


I'm sorry for the broad question, but i'm just 18yo and this is (was supposed to be) my first commercial project, but now i'm just plain confused.


P.S. sorry if this is the wrong forum, but i really couldn't think of a better one.