The document discusses several design patterns including Singleton, Factory Method, Strategy, and others. It provides descriptions of the patterns, examples of how they can be implemented in code, and discusses how some patterns like Singleton can be adapted for multi-threaded applications. It also briefly introduces the Multiton pattern, which is an extension of Singleton that allows multiple instances associated with different keys.
Exception handling - Fundamentals of exception handling, Exception types, Termination or resumptive models, Uncaught exceptions, using try and catch, multiple catch clauses, nested try statements, throw, throws and finally, built- in exceptions, creating own exception sub classes.
Multithreading- Differences between thread-based multitasking and process-based multitasking, Java thread model, creating threads, thread priorities, synchronizing threads, inter thread communication
This has been presented in association with Robosepians for Java concepts. Basic concepts of Java including features, conditional statements, loop statements, arrays, string, primitive datatypes, essentials of Java including oops concepts, classes, objects, polymorphism, advance topics including packages, exception handling, multihtreading and network programming have been discussed.
JavaScript is the language of Web. It has its own styles and vocabulary, which is very different from languages we are familiar with like C, C++, Java, C# etc. While not having classes and functions to be acting as FIRST CLASS CITIZENS for most of the tasks sometimes its difficult to manage very large JavaScript files. And, there comes the need of a common pattern for writing efficient JavaScript.
Exception handling - Fundamentals of exception handling, Exception types, Termination or resumptive models, Uncaught exceptions, using try and catch, multiple catch clauses, nested try statements, throw, throws and finally, built- in exceptions, creating own exception sub classes.
Multithreading- Differences between thread-based multitasking and process-based multitasking, Java thread model, creating threads, thread priorities, synchronizing threads, inter thread communication
This has been presented in association with Robosepians for Java concepts. Basic concepts of Java including features, conditional statements, loop statements, arrays, string, primitive datatypes, essentials of Java including oops concepts, classes, objects, polymorphism, advance topics including packages, exception handling, multihtreading and network programming have been discussed.
JavaScript is the language of Web. It has its own styles and vocabulary, which is very different from languages we are familiar with like C, C++, Java, C# etc. While not having classes and functions to be acting as FIRST CLASS CITIZENS for most of the tasks sometimes its difficult to manage very large JavaScript files. And, there comes the need of a common pattern for writing efficient JavaScript.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
Introduction to JPA and Hibernate including examplesecosio GmbH
In this talk, held as part of the Web Engineering lecture series at Vienna University of Technology, we introduce the main concepts of Java Persistence API (JPA) and Hibernate.
The first part of the presentation introduces the main principles of JDBC and outlines the major drawbacks of JDBC-based implementations. We then further outline the fundamental principles behind the concept of object relation mapping (ORM) and finally introduce JPA and Hibernate.
The lecture is accompanied by practical examples, which are available on GitHub.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
16. Threads in Java
Non-Threaded Applications
Threaded Applications
Process based multitasking Vs Thread based multitasking
Thread API in Java
Creating Threads
States of a Thread
Synchronization for threads; static and non-static synchronized methods; blocks; concept of object and class locks
Coordination between threads - wait, notify and notifyAll methods for inter-thread communication
17. Applets
What are applets?
Need for Applets
Different ways of running an applet program
Applet API hierarchy
Life Cycle of an applet
Even Handlers for applets, mouse events, click events
18. Swing GUI
Introduction to AWT
Introduction to Swing GUI
Advantages of Swing over AWT
Swing API
Swing GUI Components
Event Handlers for Swing
Sample Calculator application using Swing GUI and Swing Event handling
19. JDBC
What is JDBC; introduction
JDBC features
JDBC Drivers
Setting up a database and creating a schema
Writing JDBC code to connect to DB
CRUD Operations with JDBC
Statement types in JDBC
Types of Rowset, ResultSet in JDBC
20. Access Modifiers in Java
What are access modifiers?
Default
Protected
Private
Public
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. A design pattern is not a class or a library that we can simply plug into our system; it's much more than that. It is a template that has to be implemented in the correct situation. It's not language-specific either. A good design pattern should be implementable in most—if not all—languages, depending on the capabilities of the language. Most importantly, any design pattern can be a double-edged sword— if implemented in the wrong place, it can be disastrous and create many problems for you. However, implemented in the right place, at the right time, it can be your savior.
Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. A design pattern is not a class or a library that we can simply plug into our system; it's much more than that. It is a template that has to be implemented in the correct situation. It's not language-specific either. A good design pattern should be implementable in most—if not all—languages, depending on the capabilities of the language. Most importantly, any design pattern can be a double-edged sword— if implemented in the wrong place, it can be disastrous and create many problems for you. However, implemented in the right place, at the right time, it can be your savior.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
Introduction to JPA and Hibernate including examplesecosio GmbH
In this talk, held as part of the Web Engineering lecture series at Vienna University of Technology, we introduce the main concepts of Java Persistence API (JPA) and Hibernate.
The first part of the presentation introduces the main principles of JDBC and outlines the major drawbacks of JDBC-based implementations. We then further outline the fundamental principles behind the concept of object relation mapping (ORM) and finally introduce JPA and Hibernate.
The lecture is accompanied by practical examples, which are available on GitHub.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
16. Threads in Java
Non-Threaded Applications
Threaded Applications
Process based multitasking Vs Thread based multitasking
Thread API in Java
Creating Threads
States of a Thread
Synchronization for threads; static and non-static synchronized methods; blocks; concept of object and class locks
Coordination between threads - wait, notify and notifyAll methods for inter-thread communication
17. Applets
What are applets?
Need for Applets
Different ways of running an applet program
Applet API hierarchy
Life Cycle of an applet
Even Handlers for applets, mouse events, click events
18. Swing GUI
Introduction to AWT
Introduction to Swing GUI
Advantages of Swing over AWT
Swing API
Swing GUI Components
Event Handlers for Swing
Sample Calculator application using Swing GUI and Swing Event handling
19. JDBC
What is JDBC; introduction
JDBC features
JDBC Drivers
Setting up a database and creating a schema
Writing JDBC code to connect to DB
CRUD Operations with JDBC
Statement types in JDBC
Types of Rowset, ResultSet in JDBC
20. Access Modifiers in Java
What are access modifiers?
Default
Protected
Private
Public
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. A design pattern is not a class or a library that we can simply plug into our system; it's much more than that. It is a template that has to be implemented in the correct situation. It's not language-specific either. A good design pattern should be implementable in most—if not all—languages, depending on the capabilities of the language. Most importantly, any design pattern can be a double-edged sword— if implemented in the wrong place, it can be disastrous and create many problems for you. However, implemented in the right place, at the right time, it can be your savior.
Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. A design pattern is not a class or a library that we can simply plug into our system; it's much more than that. It is a template that has to be implemented in the correct situation. It's not language-specific either. A good design pattern should be implementable in most—if not all—languages, depending on the capabilities of the language. Most importantly, any design pattern can be a double-edged sword— if implemented in the wrong place, it can be disastrous and create many problems for you. However, implemented in the right place, at the right time, it can be your savior.
Rammar eru almennar aðgerðir og aðferðir sem nota má til að búa til sértækan hugbúnað. Með römmum má endurnýta kóða sem alltaf er eins eða nánast alltaf er eins. Það sem er sérhæft eru ákveðin viðfangsefni en útfærsla á þeim notar rammann. Við skilgreinum ramma og skoðum kosti og galla.
Við skoðum einnig létta gáma eða lightweight containers sem eru forrit sem sjá um lífshlaup (live-cycle) hluta og umhverfi þeirra (context). Þá skoðum við munstrið Dependency Injection sem er mjög hentugt í römmum.
Einnig skoðum við Template Method og Strategy munstrin.
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Mohammad Shaker
In my MSc. thesis, I have re-tackled the problem of procedurally generating content for physics-based games I have previously investigated in my BSc. graduation thesis. This time around I propose two novel methods: the first is projection based for faster generation of physics-based games content. The other, The Progressive Generation, is a generic, wide-range, across genre, customisable with playability check method all bundled in a fast progressive approach. This new method is applied on two completely different games: NEXT And Cut the Rope.
Short, Matters, Love - Passioneers Event 2015Mohammad Shaker
Short, Matters, Love is a presentation I prepared for freshmen students at the Faculty of Information Technology in Damascus, Syria organised by Passioneers - 2015
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Modern design is crucial in today's digital environment, and this is especially true for SharePoint intranets. The design of these digital hubs is critical to user engagement and productivity enhancement. They are the cornerstone of internal collaboration and interaction within enterprises.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Strategies for Successful Data Migration Tools.pptxvarshanayak241
Data migration is a complex but essential task for organizations aiming to modernize their IT infrastructure and leverage new technologies. By understanding common challenges and implementing these strategies, businesses can achieve a successful migration with minimal disruption. Data Migration Tool like Ask On Data play a pivotal role in this journey, offering features that streamline the process, ensure data integrity, and maintain security. With the right approach and tools, organizations can turn the challenge of data migration into an opportunity for growth and innovation.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Hivelance Technology
Cryptocurrency trading bots are computer programs designed to automate buying, selling, and managing cryptocurrency transactions. These bots utilize advanced algorithms and machine learning techniques to analyze market data, identify trading opportunities, and execute trades on behalf of their users. By automating the decision-making process, crypto trading bots can react to market changes faster than human traders
Hivelance, a leading provider of cryptocurrency trading bot development services, stands out as the premier choice for crypto traders and developers. Hivelance boasts a team of seasoned cryptocurrency experts and software engineers who deeply understand the crypto market and the latest trends in automated trading, Hivelance leverages the latest technologies and tools in the industry, including advanced AI and machine learning algorithms, to create highly efficient and adaptable crypto trading bots
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
Keep tabs on your field staff effortlessly with Informap Technology Centre LLC. Real-time tracking, task assignment, and smart features for efficient management. Request a live demo today!
For more details, visit us : https://informapuae.com/field-staff-tracking/
In software engineering, the right architecture is essential for robust, scalable platforms. Wix has undergone a pivotal shift from event sourcing to a CRUD-based model for its microservices. This talk will chart the course of this pivotal journey.
Event sourcing, which records state changes as immutable events, provided robust auditing and "time travel" debugging for Wix Stores' microservices. Despite its benefits, the complexity it introduced in state management slowed development. Wix responded by adopting a simpler, unified CRUD model. This talk will explore the challenges of event sourcing and the advantages of Wix's new "CRUD on steroids" approach, which streamlines API integration and domain event management while preserving data integrity and system resilience.
Participants will gain valuable insights into Wix's strategies for ensuring atomicity in database updates and event production, as well as caching, materialization, and performance optimization techniques within a distributed system.
Join us to discover how Wix has mastered the art of balancing simplicity and extensibility, and learn how the re-adoption of the modest CRUD has turbocharged their development velocity, resilience, and scalability in a high-growth environment.
3. Gamma et al, Design Patterns: Elements of Reusable Object-Oriented SoftwareAddison Wesley, 1995
4. Scope
•Patterns solve software structural problems like:
–Abstraction,
–Encapsulation
–Information hiding
–Separation of concerns
–Coupling and cohesion
–Separation of interface and implementation
–Single point of reference
–Divide and conquer
•Patterns also solve non-functional problems like:
–Changeability
–Interoperability
–Efficiency
–Reliability
–Testability
–Reusability
5. Types of Pattern
•There are 3 types of pattern:
–Creational: address problems of creating an object in a flexible way. Separate creation, from operation/use.
–Structural: address problems of using O-O constructs like inheritance to organize classes and objects
–Behavioral: address problems of assigning responsibilities to classes. Suggest both static relationships and patterns of communication
8. Patterns
•Singleton
–Ensure a class only has one instance
–Provide a global point of access to it
•Abstract Factory
–Provide an interface for creating families of related or dependent objects without specifying their concrete classes
•Factory Method
–Define an interface for creating an object but let subclasses decide which class to instantiate
–Lets a class defer instantiation to subclasses
•Prototype
–Specify the kinds of objects to create using a prototypical instance
–Create new objects by copying this prototype
9. Patterns
•Builder
–Separate the construction of a complex object from its representation so that the same construction process can create different representations
•Composite
–Compose objects into tree structures to represent part-whole hierarchies
–Lets clients treat individual objects and compositions of objects uniformly
•Decorator
–Attach additional responsibilities to an object dynamically
–Provide a flexible alternative to subclassingfor extending functionality
•Adapter
–Convert the interface of a class into another interface clients expect
–Lets classes work together that couldn’t otherwise because of incompatible interfaces
•Bridge
–Decouple an abstraction from its implementation so that the two can vary independently
10. Patterns
•Façade
–Provide a unified interface to a set of interfaces in a subsystem
–Defines an higher-level interface that makes the system easier to use
•Flyweight
–Use sharing to support large numbers of fine-grained objects efficiently
•Proxy
–Provide a surrogate or placeholder for another object to control access to it
•Iterator
–Provide a way to access the elements of an aggregate object without exposing its representation
•Command
–Encapsulate a request as an object, thereby letting you parameterize clients with different requests
11. Patterns
•Interpreter
–Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language
•Mediator
–Define an object that encapsulate how a set of objects interact
–Promotes loose coupling by keeping objects from referring to each other explicitly
–Lets you vary their interaction independently
•Memento
–Capture and externalize an object’s internal state
•Observer
–Define a one-to-many dependency between objects so when one of them change state all its dependents are updated automatically
•State
–Allow an object to alter its behavior when its internal state changes
–The object will appear to change its class
12. Patterns
•Visitor
–Represent an operation to be performed on the elements of an object structure
–Lets you define a new operation without changing the classes of the elements on which operates
•Strategy
–Define a family of algorithms
–Encapsulate each one
–Make them interchangeable
–Lets the algorithms vary independently from clients that use it
•Chain of responsibilities
–Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request
–Chain the receiving objects and pass the request along the chain until an object handles it
14. FactoryDefine an interface for creating an object but let subclasses decide which class to instantiate. Lets a class defer instantiation to subclasses
15. Factory
class ProductClass
{
public ProductClass() { … }
public ProductClass( intaInitValue) { … }
};
class FactoryClass
{
public ProductClassGetNewInstance()
{ return new ProductClass(); }
public ProductClassGetNewInstance( intaInitValue)
{ return new ProductClass( aInitValue); }
};
class Client
{
public void start()
{
// create a new factory
ProductFactorylFactory= new Factory();
// create objects
ProductClasslObj1 = lFactory.GetNewInstance();
ProductClasslObj2 = lFactory.GetNewInstance(4);
}
};
16. Factory
class ProductClass
{
public ProductClass() { … }
public ProductClass( intaInitValue) { … }
};
class FactoryClass
{
public ProductClassGetNewInstance()
{ return new ProductClass(); }
public ProductClassGetNewInstance( intaInitValue)
{ return new ProductClass( aInitValue); }
};
class Client
{
public void start()
{
// create a new factory
ProductFactorylFactory= new Factory();
// create objects
ProductClasslObj1 = lFactory.GetNewInstance();
ProductClasslObj2 = lFactory.GetNewInstance(4);
}
};
17. StrategyDefines a family of algorithms, encapsulates each algorithm, andmakes the algorithms interchangeable within that family.
18. Strategy
public interface IBehaviour{public intmoveCommand();}
public class AgressiveBehaviourimplements IBehaviour{
public intmoveCommand(){AgressiveBehaviour Behaviour}
}
public class DefensiveBehaviourimplements IBehaviour{
public intmoveCommand(){DefensiveBehaviour Behaviour}
}
public class NormalBehaviourimplements IBehaviour{
public intmoveCommand(){NormalBehaviour Behaviour}
}
public class Robot {
IBehaviourbehaviour;
String name;
public Robot(String name)
{this.name = name;}
public void setBehaviour(IBehaviourbehaviour)
{this.behaviour= behaviour;}
public void move()
{behaviourزmoveCommand();}
}
19. Strategy
public interface IBehaviour{public intmoveCommand();}
public class AgressiveBehaviourimplements IBehaviour{
public intmoveCommand(){AgressiveBehaviour Behaviour}
}
public class DefensiveBehaviourimplements IBehaviour{
public intmoveCommand(){DefensiveBehaviour Behaviour}
}
public class NormalBehaviourimplements IBehaviour{
public intmoveCommand(){NormalBehaviour Behaviour}
}
public class Robot {
IBehaviourbehaviour;
String name;
public Robot(String name)
{this.name = name;}
public void setBehaviour(IBehaviourbehaviour)
{this.behaviour= behaviour;}
public void move()
{behaviourزmoveCommand();}
}
Three different Strategies for Robot movement
20. Strategy
public interface IBehaviour{public intmoveCommand();}
public class AgressiveBehaviourimplements IBehaviour{
public intmoveCommand(){AgressiveBehaviour Behaviour}
}
public class DefensiveBehaviourimplements IBehaviour{
public intmoveCommand(){DefensiveBehaviour Behaviour}
}
public class NormalBehaviourimplements IBehaviour{
public intmoveCommand(){NormalBehaviour Behaviour}
}
public class Robot {
IBehaviourbehaviour;
String name;
public Robot(String name)
{this.name = name;}
public void setBehaviour(IBehaviourbehaviour)
{this.behaviour= behaviour;}
public void move()
{behaviourزmoveCommand();}
}
Assigning a robot behaviour
21. Strategy
public interface IBehaviour{public intmoveCommand();}
public class AgressiveBehaviourimplements IBehaviour{
public intmoveCommand(){AgressiveBehaviour Behaviour}
}
public class DefensiveBehaviourimplements IBehaviour{
public intmoveCommand(){DefensiveBehaviour Behaviour}
}
public class NormalBehaviourimplements IBehaviour{
public intmoveCommand(){NormalBehaviour Behaviour}
}
public class Robot {
IBehaviourbehaviour;
String name;
public Robot(String name)
{this.name = name;}
public void setBehaviour(IBehaviourbehaviour)
{this.behaviour= behaviour;}
public void move()
{behaviourزmoveCommand();}
}
public static void main(String[] args) {
Robot r1 = new Robot("Big Robot");
Robot r2 = new Robot("George v.2.1");
Robot r3 = new Robot("R2");
r1.setBehaviour(new AgressiveBehaviour());
r2.setBehaviour(new DefensiveBehaviour());
r3.setBehaviour(new NormalBehaviour());
r1.move();
r2.move();
r3.move();
r1.setBehaviour(new DefensiveBehaviour());
r2.setBehaviour(new AgressiveBehaviour());
r1.move();
r2.move();
r3.move();
}
22. Strategy
public interface IBehaviour{public intmoveCommand();}
public class AgressiveBehaviourimplements IBehaviour{
public intmoveCommand(){AgressiveBehaviour Behaviour}
}
public class DefensiveBehaviourimplements IBehaviour{
public intmoveCommand(){DefensiveBehaviour Behaviour}
}
public class NormalBehaviourimplements IBehaviour{
public intmoveCommand(){NormalBehaviour Behaviour}
}
public class Robot {
IBehaviourbehaviour;
String name;
public Robot(String name)
{this.name = name;}
public void setBehaviour(IBehaviourbehaviour)
{this.behaviour= behaviour;}
public void move()
{behaviourزmoveCommand();}
}
public static void main(String[] args) {
Robot r1 = new Robot("Big Robot");
Robot r2 = new Robot("George v.2.1");
Robot r3 = new Robot("R2");
r1.setBehaviour(new AgressiveBehaviour());
r2.setBehaviour(new DefensiveBehaviour());
r3.setBehaviour(new NormalBehaviour());
r1.move();
r2.move();
r3.move();
r1.setBehaviour(new DefensiveBehaviour());
r2.setBehaviour(new AgressiveBehaviour());
r1.move();
r2.move();
r3.move();
}
Simply change the Strategy and the behavior will change
23. SingletonWhen one, and only one, instance of class is needed. Providing a global point of access to it.
24. Singleton
private readonlySqlConnection_sqlConnection;
constCONNECTION_STRING = (@"Data Source=127.0.0.1;database=soa;Userid=sa1;Password=sa1;“;
public static SqlConnectionGetSqlConnectionSingleton()
{
if (_sqlConnection== null)
{
_sqlConnection= new SqlConnection(CONNECTION_STRING );
}
return _sqlConnection;
}
Any client will call GetSqlConnectionSingleton(public) and has no direct access to _sqlConnection(private)
25. Singleton for an Object
publicsealedclassSingleton
{
privatestaticSingleton _instance;
privateSingleton() { }
publicstaticSingleton GetSingleton()
{
if(_instance == null) _instance = newSingleton();
return_instance;
}
}
No one can instantiate this (since the constructor is private), like this:
Singleton s = new Singleton();
26. Singleton for an Object
publicsealedclassSingleton
{
privatestaticSingleton _instance;
privateSingleton() { }
publicstaticSingleton GetSingleton()
{
if(_instance == null) _instance = newSingleton();
return_instance;
}
}
One Instance and One Instance Only will be Created for this Class Object
27. Database ConnectionSingleton
private readonlySqlConnection_sqlConnection;
constCONNECTION_STRING = (@"Data Source=127.0.0.1;database=soa;Userid=sa1;Password=sa1;“;
public static SqlConnectionGetSqlConnectionSingleton()
{
if (_sqlConnection== null)
{
_sqlConnection= new SqlConnection(CONNECTION_STRING );
}
return _sqlConnection;
}
28. Database Connection Singleton
private readonlySqlConnection_sqlConnection;
constCONNECTION_STRING = (@"Data Source=127.0.0.1;database=soa;Userid=sa1;Password=sa1;“;
public static SqlConnectionGetSqlConnectionSingleton()
{
if (_sqlConnection== null)
{
_sqlConnection= new SqlConnection(CONNECTION_STRING );
}
return _sqlConnection;
}
29. Singleton for an Object in Multi-threaded Application? Any Need to Adjust?
31. MultitonIs an extension of the singleton pattern. When one, and only one, instance of class is needed that corresponds to a key. Providing a global point of access to it.