Click here to Skip to main content
15,890,579 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: Laptop Problem with Black Screen Pin
Kaaron7-Oct-15 14:19
Kaaron7-Oct-15 14:19 
QuestionIn fear of bloated Statergy Pattern Implementations Pin
popchecker22-Sep-15 21:03
popchecker22-Sep-15 21:03 
AnswerRe: In fear of bloated Statergy Pattern Implementations Pin
Eddy Vluggen22-Sep-15 23:27
professionalEddy Vluggen22-Sep-15 23:27 
SuggestionRe: In fear of bloated Statergy Pattern Implementations Pin
Richard Deeming23-Sep-15 1:49
mveRichard Deeming23-Sep-15 1:49 
AnswerRe: In fear of bloated Statergy Pattern Implementations Pin
jschell3-Oct-15 7:04
jschell3-Oct-15 7:04 
QuestionCan we configure team foundation server (TFS) on our local machine such as windows 7 or windows 8 Pin
Anjani Rajdev22-Sep-15 3:11
Anjani Rajdev22-Sep-15 3:11 
QuestionWindows 10 System Colors Pin
jung-kreidler11-Sep-15 1:52
jung-kreidler11-Sep-15 1:52 
QuestionSOLID Principles, Three Layers... Is this okey? Pin
MarkosElCojudo5-Sep-15 8:35
MarkosElCojudo5-Sep-15 8:35 
I've done things wrong, I confess, now I'm paying the consequences with an endless refactoring.
I'm trying to adpopt a new working paradigm.
I'll expose a concrete case, to make myself clear.

The application is about Recipes. User adds a new recipe, the application takes the information of that recipe and calculates the time it will take to cook it. Then the data is stored on a database, so you can read it again in the future.

Paradigm i've chosen so far:

1) Recipe: object to interact with the UI only has properties:
VB
Public Class Recipe
     Public Property Name
     Public Property Ingredients as list(of Ingredient) 'Meat, potato, etc.
     Public Property CookingWays as List(Of String) 'Frying, Roasting, etc.
End Class



2) Class to interact with the database
VB
Public Class Persister
      Public Sub Register(Rec as Recipe ) 
           'Process that inserts the data stored in Recipe to Database
      End sub
      Public Function GetObject(Rec as Recipe, id as Long)   as Recipe
           'Process that fills a Recipe Instance with the data from DataBase
            Return Rec
      End sub

End Class


3) A Class Factory. I call a method of this class inserting as parameter as string and get a new object.
VB
Public Class Factory
      Public Function Instatiate(Recipe as String) 
           Return New Recipe
      End sub

      Public Function Instatiate(Recipe as String, id As Long) 
           Dim rec as recipe = Instantiate("Recipe") 'New empty recipe
           Persister.GetRecipe(rec, id) 'I get a recipe object filled with information from database
      End sub

End Class



4) Overload methods in the Validator Class and throw an exception if something isn t correct.
VB
Public Class Validator
      Public Sub Validate(Rec as Recipe)   
            'Logic validation for recipe. If it doesn't pass throw exception
      End sub
        Public Sub Validate(Ing as Ingredient)   
            'Logic validation for ingredient class. If it doesn't pass throw exception
      End sub
 

End Class


5) FormManager: this class takes "objects" (like recipes or ingredients) and depending of what we want to (insert new, modify existing) shows the form

VB
Public Class FormManager
      Public Function Insert(Rec as Recipe) as Recipe
            RecipeForm.Action = "Insert"
            RecipeForm.Show()
            Dim Val as new Validator
            Val.Validate(RecipeForm.ObjectInUse)
            Return RecipeForm.ObjectInUse
      End sub
      Public Sub Insert(Ing as Ingredient)   as Recipe
            IngredientForm.Action = "Insert"
            IngredientForm.Show()
            Dim Val as new Validator
            Val.Validate(IngredientForm.ObjectInUse)
            Return IngredientForm.ObjectInUse
      End sub
'Each form is built to change its appeareance and behaviour according to the action to perform. For example sets a title like "New Recipe" or "Modify ingredient". 
End Class


6) RecipeManager: it will do te magic, uses all the other classes
VB
Public Class RecipeManager 
     Public Function CreateRecipe As Integer       'User set the recipe, it is stored in database and returns cooking time.
          Dim fac as new Factory
          Dim Rec =  Fac.Instantiate("Recipe")

          Dim f as new FormManager
          rec = f.Insert(Rec)

        'When the form is closed if the user said:
	'-"Cancel" : returns nothing.
	'-"Save": Calls the Validaror class, if it's ok => returns the Recipe object with its properties.

          

          If Rec is Nothing Then
               Exit Function
          Else
              
               Dim per as new Persister
               Per.Register(Rec)
          End If

          Return GetTime(Rec)

     End Sub

     Private Function GetTime(RecipeToAnalyse as Recipe) as Integer 'minutes to make the meal
          'Complex process that calculate the time
     End sub
      
End Class 


Now analysing the Principles:

1) Single responsability: Okey. Every class do the thing they were made for.
2) Open Closed Principle: If I'd like to add functionality tomorrow, lets say I want to add a property to the recipe which is called ToolsNeeded. It tells you what knifes bowls or microwave you need to cook it. I could make new subclasess like:

New Class
-RecipeWithTools: Inherits Recipe and adds the property ToolsNeeded

I overload new methods to this classes:

-FormManager: Shows an extra textbox where you write the tools.
-Validator: Check object RecipeWithTools has value in the ToolsNeeded property.
-Factory: Instatiate(RecipeWithTools) and Instatiate(RecipeWithTools, id):
-Persister: adds method Register(RecipeWithTools, Select): Register(RecipeWithTools, Insert): Register(RecipeWithTools, Delete): Register(RecipeWithTools, Update)

Stays the same:
-RecipeManager: stays the same because nothing was changed in calculation function. The Create Method is called with "RecipeWithTools" String so the factory knows it has to return a RecipeWithTools. The form manager knows it must show the textBox for the ToolsNeeded. The validator knows it has to check if the objects has the ToolsNeeded.

3) Liskov Substituion: In the new derived classes i could use the Recipe class instead of the RecipeWithTools and everything would be the same.

4) Interface segregation principle: Not using interfaces here, I understand I replaced them with inheritance. ¿It's Okey?

5) Dependency inversion principle: Eh... No clue.

On the other hand I think i have three layers separated here:
UI: FormManager
Business Logic: Recipe, RecipeManager, Factory y Validator.
Data Layer: Persister

Questions:

1) What do you think of the model?
2) Should I use an interface if i think that in the future RecipeManager is going to work with objects that have common things with a Recipe, but are not a recipe? If not, when would that be?
3) Can anyone explain to me how would principle 4 and 5 apply here?
AnswerRe: SOLID Principles, Three Layers... Is this okey? Pin
Eddy Vluggen10-Sep-15 12:04
professionalEddy Vluggen10-Sep-15 12:04 
AnswerRe: SOLID Principles, Three Layers... Is this okey? Pin
Nathan Minier30-Sep-15 7:08
professionalNathan Minier30-Sep-15 7:08 
QuestionFast Name Matching Pin
RichardGrimmer2-Sep-15 2:13
RichardGrimmer2-Sep-15 2:13 
AnswerRe: Fast Name Matching Pin
Eddy Vluggen2-Sep-15 2:21
professionalEddy Vluggen2-Sep-15 2:21 
GeneralRe: Fast Name Matching Pin
RichardGrimmer2-Sep-15 2:26
RichardGrimmer2-Sep-15 2:26 
GeneralRe: Fast Name Matching Pin
Eddy Vluggen2-Sep-15 2:35
professionalEddy Vluggen2-Sep-15 2:35 
AnswerRe: Fast Name Matching Pin
Keld Ølykke9-Sep-15 13:22
Keld Ølykke9-Sep-15 13:22 
AnswerRe: Fast Name Matching Pin
Nathan Minier30-Sep-15 7:33
professionalNathan Minier30-Sep-15 7:33 
QuestionHow to do Responsive Web Design Testing? Pin
uistreet19-Aug-15 21:11
uistreet19-Aug-15 21:11 
QuestionIs it possible to apply CSS to half of a character/word? Pin
protekconsulting18-Aug-15 20:34
protekconsulting18-Aug-15 20:34 
AnswerRe: Is it possible to apply CSS to half of a character/word? Pin
Richard Andrew x6420-Aug-15 9:57
professionalRichard Andrew x6420-Aug-15 9:57 
AnswerRe: Is it possible to apply CSS to half of a character/word? Pin
SharmaSumit21-Aug-15 19:39
SharmaSumit21-Aug-15 19:39 
QuestionI need a ardinuo programming code for blood pressure sensor display using cuff Pin
Member 1187747412-Aug-15 21:33
Member 1187747412-Aug-15 21:33 
AnswerRe: I need a ardinuo programming code for blood pressure sensor display using cuff Pin
OriginalGriff12-Aug-15 21:34
mveOriginalGriff12-Aug-15 21:34 
QuestionShould I change from a multi-window to a single-window multi-page approach? (WPF, C#) Pin
Frank R. Haugen7-Aug-15 1:42
professionalFrank R. Haugen7-Aug-15 1:42 
AnswerRe: Should I change from a multi-window to a single-window multi-page approach? (WPF, C#) Pin
Eddy Vluggen7-Aug-15 2:10
professionalEddy Vluggen7-Aug-15 2:10 
GeneralRe: Should I change from a multi-window to a single-window multi-page approach? (WPF, C#) Pin
Frank R. Haugen7-Aug-15 2:25
professionalFrank R. Haugen7-Aug-15 2:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.