background
play

Background Warwick, UK: Empirical Modelling Research Group - PDF document

1/20/2010 Background Warwick, UK: Empirical Modelling Research Group Dependency and its role in modern programming languages Antony Harfield 8 th January 2010 Joensuu, Finland: EdTech Research Group Current work A bit of history


  1. 1/20/2010 Background • Warwick, UK: Empirical Modelling Research Group Dependency and its role in modern programming languages Antony Harfield 8 th January 2010 • Joensuu, Finland: EdTech Research Group Current work A bit of history • France: international project to develop fusion • A long time ago, before Java and .NET as a renewable energy source existed… • People have been using dependency in software • Computer scientists at Warwick developed principles for using dependency and tools for building software that use dependency What is dependency? What is dependency? • Values (e.g. a total) dependent on other values • Another example of values dependent on other values from relational databases Item Quantity Amount Customer ฿ Mango 5 60.00 CustomerId, ValuableCustomers Name ฿ Coconut 1 20.00 Name, TotalSpent ฿ Durian 3 75.00 CREATE VIEW ValuableCustomers AS ฿ Order Orange 8 24.00 SELECT Name, Sum(Amount) TotalSpent OrderId, ฿ FROM Customer INNER JOIN Order ON Total 179.00 CustomerId, Customer.CustomerId = Order.CustomerId Amount WHERE Sum(Amount) > 1000 GROUP BY Name 1

  2. 1/20/2010 What is dependency? What is dependency? • Properties (e.g. cell colour) dependent on values • Properties dependent on other properties? – A bit more difficult – Requires a notion of dependency at a low level in Item Quantity Amount the application/programming language ฿ Mango 5 60.00 • But, it gives the freedom to create ฿ Coconut 1 20.00 dependencies between any objects, ฿ Durian 3 75.00 properties, and variables ฿ Orange 8 24.00 ฿ Total 179.00 Key ingredients of dependency Empirical Modelling Tools • EDEN – a general purpose modelling environment in 1. Observable (Variable, property or object) which any variable/property can depend on other 2. Definition (Formula or function) variables/properties • Web EDEN – a web-based version of EDEN currently in development • DOSTE – another general purpose dependency For example, in a spreadsheet: environment – The observable is the cell or the value displayed • ADM – a tool for defining agents with dependency in a cell • JAM – a tool for adding dependency to Java – The definition is the formula of the cell (e.g. the sum of a column of cells) Dependency is the key principle behind all these tools! EDEN example The rise of WPF myexample = window { 1. • Windows Presentation Foundation is 2. title = "Listbox Example: " // mylistbox_selecteditems[1]; Microsoft’s latest API for creating Windows 3. content = [mylistbox] 4. }; applications 5. mylistbox = listbox { • Much richer interfaces than existing Windows 6. selectmode = "browse"; 7. Forms UIs items = [ "blue", "red", "green", "yellow" ]; 8. selecteditems = [ "red" ]; 9. • Because it uses DirectX background = mylistbox_selecteditems[1]; 10. • WPF 3.5 (in .NET Framework 3.5) is considered font = "Verdana 32"; 11. width = myexample_width; 12. mature – reasonable VisualStudio integration Spot the height = mylistbox_items# 13. dependencies }; 14. 2

  3. 1/20/2010 What can you do with WPF? How do you write WPF applications? • Groovy user interfaces! • User interfaces can be written in XML, using a – The usual GUI components language called XAML – Rich drawing model for 2D and 3D • Code behind in any of the CLR languages (C#, – Animation, audio, video VB.NET, etc) – Styles, templating, layouts • In a variety of formats: • Or you could write it all in code – but XAML is – Traditional windows application much cleaner and allows you to separate your – Packaged web app presentation logic from your business logic – Silverlight RIAs (Rich Internet Applications) WPF Example EM technologies and WPF <Window x:Class="CoolShapedWindow.Mickey" • What is the connection between WPF and xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Empirical Modelling? xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title=“Mickey" AllowsTransparency="True" WindowStyle="None" Background="Transparent"> • Dependency! <Grid> <Image Source=“famousmouse.png" • Or more precisely, Microsoft’s implementation MouseLeftButtonDown="Image_MouseLeftButtonDown" MouseRightButtonDown="Image_MouseRightButtonDown"/> of .NET dependency properties </Grid> </Window> CoolShapedWindow.exe Normal properties Dependency properties • In OOP, classes usually have fields and methods • Look like normal properties, but… • But in .NET classes also have ‘properties’ that • Support change notification -> dependency wrap getters and setters: – Bind one property to another private String name; – Triggered actions public String Name { • Default value inheritance get { return name; } • Efficient storage set { name = Value; } } 3

  4. 1/20/2010 Dependency properties Binding • Most properties in WPF are dependency • A ‘binding’ is what creates the actual properties dependency • Therefore you can create dependencies • For example: between almost every aspect of your GUI <Slider Name=“SourceSlider" Value="20" /> • You can create dependency properties in your custom classes so that you can make your GUI <TextBlock Name=“TargetTextBlock“ Text=“Sawasdee Naresuan!“ ‘depend’ upon your business objects FontSize="{Binding ElementName=SourceSlider, Path=Value}"/> GettingStartedWithDataBinding.exe Binding Examples • Equivalent binding in code: • Simple dependency • Two way dependency Binding binding = new Binding(); binding.Source = SourceSlider; • Triggers binding.Path = new PropertyPath(“Value”); • Animation binding.Mode = BindingMode.OneWay; TargetTextBlock.SetBinding(FontSize, binding); • Binding is nothing new: it has been used to bind domain objects to user interfaces for some time • But (I think) WPF has brought out (or will bring out) the power of binding… Examples Examples (two-way binding) <Slider Name="FontSizeSlider" Minimum="10" Maximum="50" <Window … Value="20" Margin="3" /> Title="{Binding ElementName=MyTextBox, Path=Text}"> <TextBlock Name="MyTextBlock" Text="Hello World!" FontSize="{Binding ElementName=FontSizeSlider, Path=Value, <StackPanel> Mode=TwoWay}" Margin="3" /> <TextBox Name="MyTextBox" /> <StackPanel Orientation="Horizontal"> <Button Click="Click_SetSliderValue" Margin="5">Set Slider Value</Button> <TextBlock Name="MyTextBlock" Text="{Binding <Button Click="Click_SetTextBlockFontSize" Margin="5">Set ElementName=MyTextBox, Path=Text}" /> TextBlock FontSize</Button> … </StackPanel> GettingStartedWithDataBinding.exe GettingStartedWithDataBinding.exe 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend