Skip to content

Commit

Permalink
prototype pattern finished. and code review. #9
Browse files Browse the repository at this point in the history
  • Loading branch information
okmsbun committed Feb 22, 2024
1 parent 84e8f0e commit 54b660a
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 66 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,9 @@ cython_debug/

#OS
.DS_Store

#Dart
.dart_tool/
analysis_options.yaml
pubspec.lock
pubspec.yaml
1 change: 0 additions & 1 deletion abstract-factory/dart/command.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Soyut sınıfımızdır.
abstract class Command {
void executeCommand(String query);
}
1 change: 0 additions & 1 deletion abstract-factory/dart/connection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Soyut sınıfımızdır.
abstract class Connection {
bool openConnection();
bool closeConnection();
Expand Down
2 changes: 1 addition & 1 deletion abstract-factory/dart/custom_operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class CustomOperation {

void removeById(int id) {
_connection.openConnection();
_command.executeCommand("DELETE ...");
_command.executeCommand('DELETE ...');
_connection.closeConnection();
}
}
3 changes: 0 additions & 3 deletions abstract-factory/dart/i_database_factory.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'command.dart';
import 'connection.dart';

// Oluşturulacak ürünlere ait metotları içerir.
// Oracle ve MySQL için bunların geriye döndüreceği
// Nesneler farklı olacaktır.
abstract class IDatabaseFactory {
Connection createConnection();
Command createCommand();
Expand Down
2 changes: 1 addition & 1 deletion abstract-factory/dart/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'custom_operation.dart';
import 'oracle_database_factory.dart';

void main() {
CustomOperation customOperation = CustomOperation(OracleDatabaseFactory());
final CustomOperation customOperation = CustomOperation(const OracleDatabaseFactory());
customOperation.removeById(1);
}
2 changes: 0 additions & 2 deletions abstract-factory/dart/mysql_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ final class MysqlCommand implements Command {

@override
void executeCommand(String query) {
// Gelen sorgunun çalıştırılması için
// Gerekli operasyonel işlemler...
print('MysqlCommand: $query');
}
}
4 changes: 0 additions & 4 deletions abstract-factory/dart/mysql_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ final class MysqlConnection implements Connection {

@override
bool openConnection() {
// MySQL veri tabanı bağlantısının açılması için
// Gerekli operasyonel işlemler...
return true;
}

@override
bool closeConnection() {
// MySQL veri tabanı bağlantısının kapatılması için
// Gerekli operasyonel işlemler...
return true;
}
}
5 changes: 2 additions & 3 deletions abstract-factory/dart/mysql_database_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import 'i_database_factory.dart';
import 'mysql_command.dart';
import 'mysql_connection.dart';

// MySQL için ilişkili nesneler üretildi.
final class MysqlDatabaseFactory implements IDatabaseFactory {
const MysqlDatabaseFactory();

@override
Command createCommand() {
return MysqlCommand();
return const MysqlCommand();
}

@override
Connection createConnection() {
return MysqlConnection();
return const MysqlConnection();
}
}
2 changes: 0 additions & 2 deletions abstract-factory/dart/oracle_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ final class OracleCommand implements Command {

@override
void executeCommand(String query) {
// Gelen sorgunun çalıştırılması için
// Gerekli operasyonel işlemler...
print('OracleCommand: $query');
}
}
4 changes: 0 additions & 4 deletions abstract-factory/dart/oracle_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ final class OracleConnection implements Connection {

@override
bool openConnection() {
// Oracle veri tabanı bağlantısının açılması için
// Gerekli operasyonel işlemler...
return true;
}

@override
bool closeConnection() {
// Oracle veri tabanı bağlantısının kapatılması için
// Gerekli operasyonel işlemler...
return true;
}
}
5 changes: 2 additions & 3 deletions abstract-factory/dart/oracle_database_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import 'i_database_factory.dart';
import 'oracle_command.dart';
import 'oracle_connection.dart';

// Oracle için ilişkili nesneler üretildi.
final class OracleDatabaseFactory implements IDatabaseFactory {
const OracleDatabaseFactory();

@override
Command createCommand() {
return OracleCommand();
return const OracleCommand();
}

@override
Connection createConnection() {
return OracleConnection();
return const OracleConnection();
}
}
3 changes: 1 addition & 2 deletions builder/dart/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ void main() {

final Lesson lesson = lessonBuilder.getResult();

print("${lesson.name} - ${lesson.price} - ${lesson.discountedPrice}");
// output: Artificial Intelligence - Beginner to Advanced in 10 Minute. - 49.99 - 24.995
print('${lesson.name} - ${lesson.price} - ${lesson.discountedPrice}');
}
4 changes: 2 additions & 2 deletions builder/dart/new_student_lesson_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class NewStudentLessonBuilder implements LessonBuilder {
void getLesson() {
lesson = Lesson();
lesson.id = 1;
lesson.name = "Artificial Intelligence - Beginner to Advanced in 10 Minute.";
lesson.name = 'Artificial Intelligence - Beginner to Advanced in 10 Minute.';
lesson.price = 49.99;
}

Expand All @@ -21,7 +21,7 @@ final class NewStudentLessonBuilder implements LessonBuilder {

@override
void addLessonNote() {
lesson.lessonNote = "Hey, welcome. Your discount code has been applied!";
lesson.lessonNote = 'Hey, welcome. Your discount code has been applied!';
}

@override
Expand Down
6 changes: 3 additions & 3 deletions builder/dart/old_student_lesson_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ final class OldStudentLessonBuilder implements LessonBuilder {

@override
void getLesson() {
lesson = new Lesson();
lesson = Lesson();
lesson.id = 1;
lesson.name = "Artificial Intelligence - Beginner to Advanced in 10 Minute.";
lesson.name = 'Artificial Intelligence - Beginner to Advanced in 10 Minute.';
lesson.price = 49.99;
}

Expand All @@ -21,7 +21,7 @@ final class OldStudentLessonBuilder implements LessonBuilder {

@override
void addLessonNote() {
lesson.lessonNote = "";
lesson.lessonNote = '';
}

@override
Expand Down
10 changes: 5 additions & 5 deletions factory/dart/i_notify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ abstract class INotify {
//? Ayrıca bakınız: https://dart.dev/language/constructors#factory-constructors
factory INotify.createNotify(String type) {
switch (type) {
case "MAIL":
return MailNotify();
case "SMS":
return SmsNotify();
case 'MAIL':
return const MailNotify();
case 'SMS':
return const SmsNotify();
default:
throw "Geçersiz bildirim türü.";
throw Exception('Geçersiz bildirim türü.');
}
}
}
4 changes: 1 addition & 3 deletions factory/dart/mail_notify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ final class MailNotify implements INotify {
const MailNotify();

@override
void sendNotification(User user) {
// Mail gönderme operasyonu.
}
void sendNotification(User user) {}
}
10 changes: 5 additions & 5 deletions factory/dart/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import 'notify_factory.dart';
import 'user.dart';

void main() {
final NotifyFactory notifyFactory = NotifyFactory();
const NotifyFactory notifyFactory = NotifyFactory();

final INotify? notify = notifyFactory.createNotify("MAIL");
notify?.sendNotification(User());
final INotify? notify = notifyFactory.createNotify('MAIL');
notify?.sendNotification(const User());

// Alternatif
final INotify notify2 = INotify.createNotify("SMS");
notify2.sendNotification(User());
final INotify notify2 = INotify.createNotify('SMS');
notify2.sendNotification(const User());
}
14 changes: 4 additions & 10 deletions factory/dart/notify_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ final class NotifyFactory {
const NotifyFactory();

INotify? createNotify(String notifyType) {
if (notifyType == "SMS") {
// Buradaki nesne oluşturma süreçleri bize kalmıştır.
// Kullanıcıdan soyutlanmıştır.
// Örnek olarak burası Singleton olarak da ayarlanabilirdi.
return SmsNotify();
} else if (notifyType == "MAIL") {
// Buradaki nesne oluşturma süreçleri bize kalmıştır.
// Kullanıcıdan soyutlanmıştır.
// Örnek olarak burası Singleton olarak da ayarlanabilirdi.
return MailNotify();
if (notifyType == 'SMS') {
return const SmsNotify();
} else if (notifyType == 'MAIL') {
return const MailNotify();
}
return null;
}
Expand Down
4 changes: 1 addition & 3 deletions factory/dart/sms_notify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ final class SmsNotify implements INotify {
const SmsNotify();

@override
void sendNotification(User user) {
// SMS gönderme operasyonu.
}
void sendNotification(User user) {}
}
3 changes: 0 additions & 3 deletions factory/dart/user.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
final class User {
const User();

// Burada bildirimin gideceği kullanıcıya
// ait bilgiler bulunacaktır.
}
13 changes: 13 additions & 0 deletions prototype/dart/employee.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'i_cloneable_prototype.dart';

class Employee implements ICloneablePrototype<Employee> {
final String firstName;
final String lastName;

const Employee(this.firstName, this.lastName);

@override
Employee clone() {
return Employee(firstName, lastName);
}
}
3 changes: 3 additions & 0 deletions prototype/dart/i_cloneable_prototype.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class ICloneablePrototype<TPrototype> {
TPrototype clone();
}
7 changes: 7 additions & 0 deletions prototype/dart/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'employee.dart';

void main() {
const Employee gulizar = Employee('Gülizar', 'Yılmaz');
final Employee cloneGulizar = gulizar.clone();
print(gulizar == cloneGulizar);
}
2 changes: 1 addition & 1 deletion singleton/dart/database.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
final class Database {
const Database._privateConstructor();

static final Database instance = Database._privateConstructor();
static const Database instance = Database._privateConstructor();
}
8 changes: 4 additions & 4 deletions singleton/dart/main.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'database.dart';

void main() {
final Database db1 = Database.instance;
final Database db2 = Database.instance;
const Database db1 = Database.instance;
const Database db2 = Database.instance;

final bool equal = db1 == db2;
const bool equal = db1 == db2;

print('Database instances are equal: $equal'); //output: Database instances are equal: true
print('Database instances are equal: $equal');
}

0 comments on commit 54b660a

Please sign in to comment.