Skip to content

Commit 542fd16

Browse files
author
İbrahim Atay
committed
maintenance
0 parents  commit 542fd16

File tree

62 files changed

+2338
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2338
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '31 2 * * 4'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (github.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
32+
permissions:
33+
# required for all workflows
34+
security-events: write
35+
36+
# only required for workflows in private repositories
37+
actions: read
38+
contents: read
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
include:
44+
- language: csharp
45+
build-mode: autobuild
46+
- language: java-kotlin
47+
build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too.
48+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
49+
# Use `c-cpp` to analyze code written in C, C++ or both
50+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
# Initializes the CodeQL tools for scanning.
61+
- name: Initialize CodeQL
62+
uses: github/codeql-action/init@v3
63+
with:
64+
languages: ${{ matrix.language }}
65+
build-mode: ${{ matrix.build-mode }}
66+
# If you wish to specify custom queries, you can do so here or in a config file.
67+
# By default, queries listed here will override any specified in a config file.
68+
# Prefix the list here with "+" to use these queries and those in the config file.
69+
70+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
71+
# queries: security-extended,security-and-quality
72+
73+
# If the analyze step fails for one of the languages you are analyzing with
74+
# "We were unable to automatically build your code", modify the matrix above
75+
# to set the build mode to "manual" for that language. Then modify this step
76+
# to build your code.
77+
# ℹ️ Command-line programs to run using the OS shell.
78+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
79+
- if: matrix.build-mode == 'manual'
80+
run: |
81+
echo 'If you are using a "manual" build mode for one or more of the' \
82+
'languages you are analyzing, replace this with the commands to build' \
83+
'your code, for example:'
84+
echo ' make bootstrap'
85+
echo ' make release'
86+
exit 1
87+
88+
- name: Perform CodeQL Analysis
89+
uses: github/codeql-action/analyze@v3
90+
with:
91+
category: "/language:${{matrix.language}}"

.github/workflows/maven.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Java CI with Maven
10+
11+
on:
12+
push:
13+
branches: [ "main" ]
14+
pull_request:
15+
branches: [ "main" ]
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v3
26+
with:
27+
java-version: '17'
28+
distribution: 'temurin'
29+
cache: maven
30+
- name: Build with Maven
31+
run: sh maven.sh
32+
33+
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
34+
- name: Update dependency graph
35+
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

.gitignore

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
.idea/*
12+
*.iws
13+
*.iml
14+
*.ipr
15+
16+
### Eclipse ###
17+
.apt_generated
18+
.classpath
19+
.factorypath
20+
.project
21+
.settings
22+
.springBeans
23+
.sts4-cache
24+
25+
### NetBeans ###
26+
/nbproject/private/
27+
/nbbuild/
28+
/dist/
29+
/nbdist/
30+
/.nb-gradle/
31+
build/
32+
!**/src/main/**/build/
33+
!**/src/test/**/build/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
### Mac OS ###
39+
.DS_Store
40+
=======
41+
# Compiled class file
42+
*.class
43+
44+
# Log file
45+
*.log
46+
47+
# BlueJ files
48+
*.ctxt
49+
50+
# Mobile Tools for Java (J2ME)
51+
.mtj.tmp/
52+
53+
# Package Files #
54+
*.jar
55+
*.war
56+
*.nar
57+
*.ear
58+
*.zip
59+
*.tar.gz
60+
*.rar
61+
62+
63+
*.suo
64+
*.user
65+
.vs/
66+
[Bb]in/
67+
[Oo]bj/
68+
_UpgradeReport_Files/
69+
[Pp]ackages/
70+
71+
Thumbs.db
72+
Desktop.ini
73+
.DS_Store
74+
75+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
76+
hs_err_pid*

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[![Java CI with Maven](https://github.com/ibrahimatay/Design-Patterns/actions/workflows/maven.yml/badge.svg)](https://github.com/ibrahimatay/Design-Patterns/actions/workflows/maven.yml) [![.NET](https://github.com/ibrahimatay/Design-Patterns/actions/workflows/dotnet.yml/badge.svg)](https://github.com/ibrahimatay/Design-Patterns/actions/workflows/dotnet.yml)
2+
# Design Patterns For Humans
3+
Examples of design patterns in Java and C# are presented in a way that is easy for humans to understand and implement. The purpose of these examples is to provide a practical and intuitive guide to the use of design patterns in Java, helping developers improve their skills and create more effective and maintainable software.
4+
5+
![image](/docs/images/desing-pattern-relationships.jpeg)
6+
7+
## ***Creational***
8+
- Factory Method ([Java](/Java/factory-method), [C#](/Csharp/DesignPatterns.FactoryMethod))
9+
- Abstract Factory ([Java](/Java/abstract-factory), [C#](/Csharp/DesignPatterns.AbstractFactory))
10+
- Builder ([Java](/Java/builder), [C#](/Csharp/DesignPatterns.Builder))
11+
- Prototype ([Java](/Java/prototype), [C#](/Csharp/DesignPatterns.Prototype))
12+
- Singleton
13+
- Eager Instantiation ([Java](/Java/singleton-eager-instantiation), [C#](/Csharp/DesignPatterns.SingletonEagerInstantiation))
14+
- Lazy Instantiation ([Java](/Java/singleton-lazy-instantiation), [C#](/Csharp/DesignPatterns.SingletonLazyInitialization))
15+
- Enum-based Singleton ([Java](/Java/singleton-with-enum))
16+
- Double-Checked Locking with Singleton ([C#](/Csharp/DesignPatterns.DoubleCheckedLockingwithSingleton/))
17+
18+
## ***Structural***
19+
- Adapter ([Java](/Java/adapter), [C#](/Csharp/DesignPatterns.Adapter))
20+
- Proxy ([Java](/Java/proxy), [C#](/Csharp/DesignPatterns.Proxy))
21+
- Facade ([Java](/Java/facade), [C#](/Csharp/DesignPatterns.Facade))
22+
- Composite ([Java](/Java/composite), [C#](/Csharp/DesignPatterns.Composite))
23+
- Bridge ([Java](/Java/bridge), [C#](/Csharp/DesignPatterns.Bridge))
24+
- Flyweight ([Java](/Java/flyweight), [C#](/Csharp/DesignPatterns.Flyweight))
25+
- Decorator ([Java](/Java/decorator), [C#](/Csharp/DesignPatterns.Decorator))
26+
27+
## ***Behavioral***
28+
- Command ([Java](/Java/command), [C#](/Csharp/DesignPatterns.Command))
29+
- Iterator ([Java](/Java/iterator), [C#](/Csharp/DesignPatterns.Iterator))
30+
- Memento ([Java](/Java/memento), [C#](/Csharp/DesignPatterns.Memento))
31+
- Observer ([Java](/Java/observer) [C#](/Csharp/DesignPatterns.Observer))
32+
- Strategy ([Java](/Java/strategy), [C#](/Csharp/DesignPatterns.Strategy))
33+
- Template Method ([Java](/Java/template-method), [C#](/Csharp/DesignPatterns.TemplateMethod))
34+
- Visitor ([Java](/Java/visitor), [C#](/Csharp/DesignPatterns.Visitor))
35+
- Chain of Responsibility ([Java](/Java/chain-of-responsibility), [C#](/Csharp/DesignPatterns.ChainOfResponsibility))
36+
- Pipeline ([Java](/Java/pipeline), [C#](/Csharp/DesignPatterns.Pipeline))
37+
- State ([Java](/Java/state), [C#](/Csharp/DesignPatterns.State))
38+
- Mediator ([Java](/Java/mediator), [C#](/Csharp/DesignPatterns.Mediator))
39+
40+
## References
41+
Design patterns in this repository are based on
42+
43+
* [Design Patterns by The "Gang of Four"]
44+
* [Head First: Design Patterns]
45+
* [Wikipedia]
46+
* [Other Documents]
47+
48+
[Design Patterns by The "Gang of Four"]: https://en.wikipedia.org/wiki/Design_Patterns
49+
[Head First: Design Patterns]: http://www.headfirstlabs.com/books/hfdp/
50+
[Wikipedia]: https://en.wikipedia.org/wiki/Software_design_pattern
51+
[Other Documents]: docs

abstract-factory/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>design-patterns</artifactId>
7+
<groupId>com.ibrahimatay</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>abstract-factory</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>${java.source.version}</maven.compiler.source>
16+
<maven.compiler.target>${java.target.version}</maven.compiler.target>
17+
</properties>
18+
19+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.ibrahimatay;
2+
3+
interface Command {
4+
void execute(String query);
5+
}
6+
7+
interface Connection {
8+
void connect();
9+
void disconnect();
10+
}
11+
12+
interface DatabaseFactory {
13+
Connection createConnection();
14+
Command createCommand(Connection connection);
15+
}
16+
17+
class Db2Command implements Command {
18+
@Override
19+
public void execute(String query) {
20+
System.out.println("Db2 query executed");
21+
}
22+
}
23+
24+
class Db2Connection implements Connection {
25+
26+
@Override
27+
public void connect() {
28+
System.out.println("Connection is connected.");
29+
}
30+
31+
@Override
32+
public void disconnect() {
33+
System.out.println("Connection is disconnected.");
34+
}
35+
}
36+
37+
class Db2DatabaseFactory implements DatabaseFactory {
38+
39+
@Override
40+
public Connection createConnection() {
41+
return new Db2Connection();
42+
}
43+
44+
@Override
45+
public Command createCommand(Connection connection) {
46+
if(connection == null) {
47+
throw new NullPointerException();
48+
}
49+
return new Db2Command();
50+
}
51+
}
52+
53+
public class Main {
54+
public static void main(String[] args) {
55+
DatabaseFactory db2DatabaseFactory = new Db2DatabaseFactory();
56+
Connection connection = db2DatabaseFactory.createConnection();
57+
Command command = db2DatabaseFactory.createCommand(connection);
58+
59+
connection.connect();
60+
command.execute("select * from product");
61+
connection.disconnect();
62+
}
63+
}

adapter/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>design-patterns</artifactId>
7+
<groupId>com.ibrahimatay</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>adapter</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>${java.source.version}</maven.compiler.source>
16+
<maven.compiler.target>${java.target.version}</maven.compiler.target>
17+
</properties>
18+
19+
</project>

0 commit comments

Comments
 (0)