DDD / Repository - domain-driven-design

I am very new to DDD. My SQL table contains a list of styles, every style has colors and sizes. Now, I am working on an application, where the user will see three dropdownlists, one for style, one for the color and one for the size. Now initially these dropdownlists are loaded with the distinct values. The user is then able to select a style and the system will then able to find all colors/sizes for that selected style. The user can do the same with the color and it will load the styles that match the selected color and the sizes. You get the idea.
These are my basic requirements. Now I was thinking to create a repository for the styles (StyleRepository) and have it load all styles, and when required load the child colors, and child sizes.
However as described in my app, I will also need to load the distinct colors or sizes. Now is it recommended to create three repositories instead StyleRepository, ColorRepository, SizeRepository or would I create a totally different Repository?
As said I am fairly new to this and would appreciate your suggestions.
Thank you

Style appears to be your root aggregate object. That's what you build your Repository around.
Since each Style has a specific subset of Colors and Sizes that are allowed for that style, each Style should contain a list of Colors and Styles.
public class Style
{
public IList<Color> Colors { get; set;}
public IList<Size> Sizes { get; set;}
}
Your Repository is then going to have a FindAll() method to return all the Styles. Each Style has its own list of Colors and Sizes, so no need to hit the Repository again to get those. When the user selects a specific Style from a dropdown (hopefully you've bound the Style object) then you can just get the list of Colors and Sizes from the selected object and populate the other Dropdowns.
When a user chooses a specific Style, Color and Size, then I would assume that gets saved in a separate class, like a SelectedStyle class, which only contains one Color and Size property.
public class SelectedStyle
{
public Color Color { get; set;}
public Size Size { get; set;}
}

As colors in your case are actual colors used by styles, not just abstract color list (like in painting application), I would go with StyleRepository and addeed method like GetAllUsedColors().

Related

UILabel not wrapping in UITableView until device rotate (iOS8)

I have a custom MvxTableViewCell that is associated with an MvxStandardTableViewSource. That Source is then applied to a UITableView. The custom table cell is defined without any Storyboard or NIB. It is laid out in code and uses AutoLayout.
this.searchResultsTable = new UITableView();
this.searchResultsTable.AccessibilityIdentifier = "SearchView_SearchResultsTable";
this.searchResultsTable.TranslatesAutoresizingMaskIntoConstraints = false;
this.searchResultsTable.RowHeight = UITableView.AutomaticDimension;
this.searchResultsTable.EstimatedRowHeight = 44.0f;
this.searchResultsTable.RegisterClassForCellReuse(typeof(CustomerItemCell), new NSString("CustomerItemCell"));
this.searchResultsTable.AllowsMultipleSelectionDuringEditing = true;
this.searchResultsTable.TableFooterView = new UIView();
this.searchResultsTableDataSource = new MvxStandardTableViewSource(this.searchResultsTable, new NSString("CustomerItemCell"));
this.searchResultsTable.Source = this.searchResultsTableDataSource;
The MVxStandardTableViewSource is databound to a ViewModel property of type List
var set = this.CreateBindingSet<SearchView, SearchViewModel>();
set.Bind(this.searchResultsTableDataSource).To(vm => vm.SearchResults);
set.Bind(this.searchBar).For(x => x.Text).To(vm => vm.CurrentSearchCriteria);
set.Apply();
This all works fine until an item in the data source causes some text wrapping in one of the UILabels and consequently a different height to the other cells.
The cell height is mostly correctly calculated but the UILabel within the
cell does not get redrawn until the device is rotated. I am using iOS AutoLayout to layout the various UIViews in the Cell.
Here are some examples of the large cell in my layout, see the
person "THISISAPATIENTWITHA-" (note this is test data not real people's data)
Initial display of cells
Same cells but device has been rotated
Still the same cells with device rotated back to original
How do I get the UILabel to redraw? We only need to support iOS8 and above.
I cannot see an event or method that gets called when the data binding has happened that would allow me to effectively tell the custom cell "You now have your subviews populated with bound data so redraw them"
The table has another issue too that is covered by this question, Implementing cell reuse for varying height cells in UITableView
Simple Repro on Github
https://github.com/munkii/TableCellResizeIssue
UPDATE:
I've forked your GitHub project and submitted a pull request. But here's my updates to your project.
https://github.com/SharpMobileCode/TableCellResizeIssue
First, you're using FluentLayout for your constraints. Nothing wrong with that actually, but that's some good info to tell others. :)
Second, in order for UITableView.AutomaticDimension to work on TableView Cells, there must be enough autolayout constraints defined in order for the cell to calculate the height of the cell. UITableView.AutomaticDimension depends on proper AutoLayout constraints.
Since you were using FluentLayout to abstract iOS AutoLayout constraints, this was not obvious as no warnings were present in the application output window. Though FluentLayout was technically correct, it however wasn't enough for UITableView.AutomaticDimension to automatically calculate each cell height.
So what I did was added a few more constraints. Look in CustomerItemCell.CreateView() in the pull request (or my github link). You can see that I added additional constraints for all the bottom labels so that they add a Bottom Constraint to the ContentView (Just like you did with this.bornLabel). This had to be applied to all the labels on the bottom of the cell. This gives AutoLayout enough information to properly calculate the cell height.
Third, This almost works, but if you rotate to Landscape, you'll notice that the long name cells will be bigger and have extra padding. To fix this, I created another class called AutoLayoutLabel that inherits from UILabel. I overrode the Bounds property so that it changes the PreferredMaxLayoutWidth to the proper width when rotated to Landscape, and back to Portrait. You then will need to use AutoLayoutLabel instead of UILabel. You'll need this for all labels that need to wrap. I'm not sure how to set PreferredMaxLayoutWidth to auto in code, but this is how to do it programmatically (which also works for iOS 7).
public class AutoLayoutLabel : UILabel
{
public override CGRect Bounds
{
get
{
return base.Bounds;
}
set
{
base.Bounds = value;
if(this.Lines == 0 && Bounds.Size.Width != PreferredMaxLayoutWidth)
{
PreferredMaxLayoutWidth = Bounds.Size.Width;
SetNeedsUpdateConstraints();
}
}
}
}
Well, that should do it!
I now have a solution to this part of my issue. Prompted by #SharpMobileCode reference to PreferredMaxLayoutWidth I decided to give that another go. Rather that setting it to Automatic (which seems impossible in code) I am setting it Explicitly, once AutoLayout has done its thing. Like this
/// <summary>
/// Lays out subviews.
/// </summary>
public override void LayoutSubviews()
{
base.LayoutSubviews();
this.nameLabel.PreferredMaxLayoutWidth = this.nameLabel.Frame.Size.Width;
}
I am no longer seeing the Labels not wrap (hurrah!) however I am seeing an issue with what looks like cell reuse. Once I scroll all of the cell off the top of the screen I can scroll it back on and it has reverted to the same height as all the other cells. I can see the label is still wrapping but the cell height is wrong.
The standard table views in MvvmCross date back to iOS4 - while the new UITableViewAutomaticDimension sizing wasn't really added until much more recently (iOS8?)
Most real apps tend to use custom cells rather than the standard ones, but if you do want to use the standard ones, then I'd guess you could try adding some code to the setters in the cell which would trigger resize recalculations - e.g. to setters in https://github.com/MvvmCross/MvvmCross/blob/3.5/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxStandardTableViewCell.cs#L73
I would guess that judiciously placed calls in there to request layout recalc would cause the parent cell and table to redraw.

What layout to use when wanting to display over 10,000 textviews(Strings)

Image below is what iv constructed already, but can see the daunting task of creating it for 40 students with 250-300 entires each...What layout would i use if i was to display over 10000 textviews(strings)?
Think of it as a table where there are 40 student names down the side of the xml layout and each of these students had its own row. In that row it displayed them being absent or present with the letter A(Absent) and P(Present).
I need each student to have at least 250 entries or textviews for the school calandar year. So as you can see 250 entries multiplied by 40 students equals alot of individual textviews which is not ideal.
I am stuck on which layout to use; ListView, GridView or is there another easier layout to display all this data that is being passed from another class using the spinners of each student? So every time a user pushes the confirm button from the class with the spinners it will take that string and pass onto the class that i want to display it. Like a roll book for school. Thanks
Forget layouts here. Better draw everything completely on your own. It may be a bit more work, but you have complete control over what's going on, you don't need any XML, and you avoid surprises with the sometimes funny, sparsely documented behavior of those layouts. As a start, you create your own View class and implement a few functions:
public class UiView extends View {
#Override
protected void onDraw(Canvas canvas) {/*...*/}
#Override
public boolean onTouchEvent(MotionEvent event) {/*...*/}
}
and put it into your main layout:
<com.mytool.UiView ...
Then you have complete freedom to tune the behavior by implementing onDraw and onTouchEvent.

Text line height

How can I specify a line height in a multi-line Text / Label?
It already seems it's not supported in css:
JavaFX CSS does not support comma-separated series of font family
names in the -fx-font-family property. The optional line height
parameter when specifying fonts is not supported. There is no
equivalent for the font-variant property.
Is there a reason for this?
Is there an alternative to set this in code? Or kinda emulate the functionality? I want to control vertical rhythm within my app.
Java 8+ implementation
RT-21683 Allow to change line-to-line spacing was implemented to add a line spacing feature to JavaFX Java 8.
The line spacibg API is defined on Text, TextFlow and Labeled nodes via a lineSpacing property and associated getters and setters. Spacing is defined in pixels, like the rest of JavaFX layout.
Java 2.2- implementation
If you cannot use Java 8+, you will need to implement line spacing yourself, e.g. By setting spacing on a VBox with separate Text nodes for each line.
Discussion of unit measurements in JavaFX
It seems that there is a corresponding (stylable) css property? If it's defined in pixels, how do I make it dpi aware
css properties work can work with em units if you use them. See for example the default modena.css stylesheet which measures almost all sizes in em units. This is why if you are just using default styles without additional pixel based layout, then if you change the root font size, everything in your layout scales automatically.
It's only the Java APIs and FXML which work with only pixel units. Even then, the JavaFX system is clever enough to know (at least on some machines), that it is running on a HiDPI display (e.g. OS X retina) so that, for example, pixel units are automatically doubled for the retina display (in Java 8).
If you are using FXML, you could use expression bindings as a way to define your own unit system.
Future versions of JavaFX may provide more support for RT-14020 Concept for a screen resolution independent definition of a GUI.
Sample Code
The sample below uses the Java 8 to demonstrate usage of the lineSpacing api and -fx-line-spacing css attribute.
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class LineSpacing extends Application {
public static void main(String[] args) { launch(LineSpacing.class); }
#Override public void start(Stage stage) {
Label label = new Label(
"Power is my mistress.\n" +
"I have worked too hard at her conquest " +
"to allow anyone to take her away from me.\n" +
" - Napoleon Bonaparte");
label.setPadding(new Insets(20));
// as the default font spacing in JavaFX is 13 points,
// all of the following lines will provide the same results
// (double spacing the label text).
//
// label.setLineSpacing(13);
// label.setStyle("-fx-line-spacing: 13px;");
label.setStyle("-fx-line-spacing: 1em;");
stage.setScene(new Scene(label));
stage.show();
}
}

How should I go about making game menus that I want to fit inside a container?

I have to write an XNA game for a project in my college program. I'm making a turn-based RPG in the vein of the Gameboy Pokemon games. I'd like to align the menu options with a container at the bottom of the screen, with never more than 4 options. This should give you a rough idea about how I want the combat screen to look:
I currently have a menu system that aligns all the menu items with the center of the screen, meaning menus end up looking like this:
Start Game
Options
Quit
but in the center of the screen.
What is the best way to position the menu items in a similar fashion to the image above? Should I hardcode in the positions for the menu items, should I try and make some kind of class to act as the container for these items and have their position be relative to the size and position of the container, or use some other method?
If you don't want to hardcode the positions it could get pretty complex, depending on how much flexibility you want.
I would create a container class which is part of a tree structure, (see scene graph), with a parent container and a list of child containers. That is the most common way of handling relative positioning. Here a quick example:
public class Container
{
public Container Parent { get; set; }
public List<Container> Children { get; set; }
public Vector2 RelativePosition { get; set; }
public Vector2 AbsolutePosition
{
get
{
// The container is the root node
if (Parent == null)
return RelativePosition;
else
return RelativePosition + Parent.AbsolutePosition;
}
}
}
If you need even more flexibilty you could create a floated layout, where the elements are positioned dynamically depending on their size.
As stated by Lucius, creating a Container class is the best solution.
Currently I'm developing an UI application for the XBox.
Therefor I needed something like a positioning engine, with everything being relative, so I didn't need to calculate pixel stuff everytime.
What I did was creating a Container class, which contains roughly following attributes:
VectorTopLeft (Which the element which contains a Container object uses for drawing)
VectorTopRight
VectorBottomLeft
VectorBottomRight
Align (Enum: Right, Center, Left)
VerticalAlign (Enum: Top, Middle, Bottom)
NewRow (bool)
PreviousContainer (Container)
ParentContainer (Container)
Width (Getter)
Height (Getter)
PercentageHeight (getter/setter) (Percentage of the height of the parent container)
PercentageWidth (getter/setter) (Percentage of the width of the parent container)
PixelHeight (getter/setter) (Absolute height in pixels)
PixelWidth (getter/setter) (Absolute width in pixels)
AspectRatio: Used for setting the width to a ratio of the height, usefull for different screen aspects (4/3 or 16/9 for example)
MarginLeft
MarginRight
MarginTop
MarginBottom
The following vectors include margins, these are vectors used by the alignment procedure.
AbsoluteVectorTopLeft
AbsoluteVectorTopRight
AbsoluteVectorBottomLeft
AbsoluteVectorBottomRight
The following size attributes also include margins, usefull for calculating remaining sizes
AbsoluteWidth (getter)
AbsoluteHeight (getter)
And then some flags which get set to true if something crucial changes, and vectors/size stuff needs to be recalculated.
The alignment stuff is pretty complex, as in the fact that it uses recursion, and also calls previous container functions to shift everything to the right place.
The newrow attribute tells the system that it needs to start the element at a new row in the parent container, and is used for keeping the vertical alignment in mind.
The system might have some minor flaws, but at this moment it works as a charm for all my GUI related positioning stuff, and it works pretty damn fast!

Name of control for toggle boxes in sharepoint editor part

I'm trying to modify the EditorPart controller for my web part. Basically what I want is to have my custom controls inside a box like the standard properties that can toggle between visible and hidden.
I've been googling for a while, but I cannot seem to find an answer.
Just to clarify: I know I can use the Category property to accomplish this when adding web part properties directly to the web part, but I've extended the EditorPart controller and so I don't think I can simply add [Category("Feed settings")] to the TextBox and LiteralControls I'm creating (correct?).
What you'd need for a standard property is to mark it with the Category attribute:
[Category("My Category")]
public string FeedQuery { get; set; }
(You'll need to add the System.ComponentModel namespace to your class file).
For editor parts it is not so simple. It appears that you can't add them to the standard categories. It is possible to style the editor part to resemble the OOB panels as shown here

Resources