Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
entwurfsmuster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mki-swt2
entwurfsmuster
Commits
2c457f9c
Commit
2c457f9c
authored
4 years ago
by
Peter Hertkorn
Browse files
Options
Downloads
Patches
Plain Diff
Add dynamic loading of pizza classes (NY style)
parent
7c0cb856
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pizzeria/NYPizzaStore.java
+19
-10
19 additions, 10 deletions
src/pizzeria/NYPizzaStore.java
src/pizzeria/nypizza.properties
+5
-0
5 additions, 0 deletions
src/pizzeria/nypizza.properties
with
24 additions
and
10 deletions
src/pizzeria/NYPizzaStore.java
+
19
−
10
View file @
2c457f9c
package
pizzeria
;
import
java.io.IOException
;
import
java.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.Properties
;
public
class
NYPizzaStore
extends
PizzaStore
{
Pizza
createPizza
(
String
item
)
{
if
(
item
.
equals
(
"cheese"
))
{
return
new
NYStyleCheesePizza
();
}
else
if
(
item
.
equals
(
"veggie"
))
{
return
new
NYStyleVeggiePizza
();
}
else
if
(
item
.
equals
(
"clam"
))
{
return
new
NYStyleClamPizza
();
}
else
if
(
item
.
equals
(
"pepperoni"
))
{
return
new
NYStylePepperoniPizza
();
}
else
return
null
;
Pizza
pizza
=
null
;
Properties
properties
=
new
Properties
();
try
{
properties
.
load
(
this
.
getClass
().
getResourceAsStream
(
"nypizza.properties"
));
String
pizzaName
=
properties
.
getProperty
(
item
);
Class
<?>
classOfPizza
=
Class
.
forName
(
pizzaName
);
Constructor
<
Pizza
>
constructor
=
(
Constructor
<
Pizza
>)
classOfPizza
.
getConstructor
(
new
Class
[]{});
pizza
=
constructor
.
newInstance
();
}
catch
(
IOException
|
ClassNotFoundException
|
InstantiationException
|
IllegalAccessException
|
NoSuchMethodException
|
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
return
pizza
;
}
}
This diff is collapsed.
Click to expand it.
src/pizzeria/nypizza.properties
0 → 100644
+
5
−
0
View file @
2c457f9c
cheese
=
pizzeria.NYStyleCheesePizza
clam
=
pizzeria.NYStyleClamPizza
pepperoni
=
pizzeria.NYStylePepperoniPizza
veggie
=
pizzeria.NYStyleVeggiePizza
salami
=
pizzeria.NYStyleSalamiPizza
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment