dimanche 3 juillet 2016

Models hierarchical structure

I worked on java project have single hierarchical structure for database models (data base accesses objects)

this structure has single path hierarchy which like that

Hierarchy Diagram

On application load create single object of LastModel class and every time need to use model call method which return that object.

what is name for this pattern?

what is advantages and disadvantage of use it?

can use it for huge applications?

samedi 2 juillet 2016

C# Obects & Methods

Can I create the below class structure? Is this a good design?

class Employee 
{

    public FirstName {get;set;}
    public LastName { get;set;}

    public string GetEmployeeName()
    {
        // database or service call

        return FirstName+LastName;
    }
}

If I create a class like this, how do I properly unit test? Can I implement an interface in this call? Is there any specific design pattern stating this design?

Thanks

Is it OK to use covariance of types with abstract factory pattern

I'm learning about design patterns from GOF book.

There is one thing about Abstract Factory pattern implementation that makes me mingle. I'll start with code:

Abstract Factory:

public interface AnimalsFactory {

    Animal getWaterAnimal();

    Animal getLandAnimal();

    Animal getFlyingAnimal();
}

Concrete Factory:

public class SafariAnimalsFactory implements AnimalsFactory {

    @Override
    public Hippo getWaterAnimal() {
        return new Hippo();
    }

    @Override
    public Giraffe getLandAnimal() {
        return new Giraffe();
    }

    @Override
    public Lion getFlyingAnimal() {
        return new Lion();
    }
}

I used covariance of types so factory methods return concrete products instead of abstract products (Animal).

I like it but doesn't this violate rule of thumb about products being encapsulated from the client? Or maybe I'am overthinking this.

If this is too much opinion based question I'm willing to delete it.

DRY JavaScript Inheritance from Within a Constructor

Is it possible to get Dog and Cat to inherit from Animal (without using the class or extends keywords), without editing the code that has already been written, and while keeping all new code within the current constructor functions?

function Animal() {
  this.sleep = function() {
    var hoursSleepPerNight = this.hoursSleepPerNight;
    console.log( "z".repeat(hoursSleepPerNight) );
  }
}

function Dog() {
  this.hoursSleepPerNight = 8;
}

function Cat() {
  this.hoursSleepPerNight = 7;
}

var dog = new Dog();
var dog.sleep;
// "zzzzzzzz"

webdev - swapping data within div

I'm a novice in webdev.

Terminology, phrasing, and conventions are still in the works. Without the right wording, researching my problem -- with books, Google, and SO -- was unsuccessful. Maybe the goal will make sense:

I have an outer < div > acting as a tab-based display. Within, I plan to add a scroll-able list and a 'show area' consisting of various content (images, text, apps, etc). Retrospectively, the format is similar to Outlook's and iOS' mail design.

The tabs are one category of data, the list items another. This is akin to different mail folders (e.g. Junk Mail -> mail item 3 -> display contents; Inbox -> mail item 2 -> display contents).

My concern is how to display those contents, since there is a wide range of possible selections and much substance to each. I cannot imagine hiding all but the selected < div >, which would be like hiding all mail items besides the current one.

I thought of creating local files and reading them based on item selection. Even then, I am unsure what would be effective. If it were only some text, I could easily swap the innerHTML of the displaying < div >. But would that be useful for my intention?

Overall, how would I go about this design? What are particular terms or design concepts that you may recommend for thinking about this and similar problems?

Thank you for the time!

c# Repository with Two Data Providers

I am creating one repository and I have to deal with two data providers(IFileDataAccess, IDbDataAccess) to build my model object(MyModel).

I have written below code, but I feel it's not correct, it's important to have MyModel class with all written properties as they all be used together.

Please suggest a good way to achieve this.

Thanks!

class MyModel
    {
    public Schedule Schedule { get; set; }
    public Rates Rates { get; set; }
    public Balance Balance { get; set; }
    }

class MyRepository 
{
    private IFileDataAccess  _fileDataAccess;
    private IDbDataAccess  _dbDataAccess;

    public MyClass (IFileDataAccess fileDataAccess, IDbDataAccess dbDataAccess)
    {
        _fileDataAccess= fileDataAccess;
        _dbDataAccess=dbDataAccess;
    }

    public MyModel GetMyModel()
{
    return new MyModel(){Schedule=_dbDataAccess.GetSchedule(),Rates=_fileDataAccess.GetRates(), Balance=_fileDataAccess.GetBalance()};
}

}

Unity Container with Composition Root

I am new to DI and unity container. I am trying to use Unity with Composition Root. I have all my unity mappings/registrations in app.config file and just want to centralise all the resolve calls for my application.

The Application has many classes and very nested object graph created using constructor injection. So in a centralise location I want to create this object graph and then start make the call to do the actual work.

Please suggest a good way to implement composition root with unity.

Thanks!