Skip to content

Commit

Permalink
Observer design pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanKomcu committed Mar 20, 2022
1 parent 8e64f3a commit 4372bfd
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
14 changes: 14 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/IObserver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Design_Pattern
{
public interface IObserver
{

void Update();
}
}
16 changes: 16 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/MobilApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Design_Pattern
{
public class MobilApp : IObserver
{
public void Update()
{
Console.WriteLine("New news has been added to the application.");
}
}
}
42 changes: 42 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/News_Website.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Design_Pattern
{
public class News_Website
{

public string News_Name { get; set; }
public string Explanation { get; set; }



public bool New_News { get; set; }



List<IObserver> observers;
public News_Website()
{
this.observers = new List<IObserver>();
}
//Gözlemci ekle
public void Client_Add(IObserver observer)
{
observers.Add(observer);
}
//Gözlemci çıkar

public void Notify()
{
observers.ForEach(g =>
{
g.Update();
});
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{05577F65-2CC7-4B2C-871C-3D7424FAE50C}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Observer_Design_Pattern</RootNamespace>
<AssemblyName>Observer_Design_Pattern</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="News_Website.cs" />
<Compile Include="Website.cs" />
<Compile Include="MobilApp.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IObserver.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
31 changes: 31 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Design_Pattern
{
internal class Program
{
static void Main(string[] args)
{
News_Website news_Website = new News_Website();
news_Website.News_Name = "Looking for new in technology";
news_Website.Explanation = "Oğuzhan's new product was met with great interest and received a lot of investment.";
news_Website.New_News = true;


if (news_Website.New_News == true)
{
news_Website.Client_Add(new MobilApp());
news_Website.Client_Add(new Website());
news_Website.Notify();
}



Console.ReadKey(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Observer_Design_Pattern")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Observer_Design_Pattern")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("05577f65-2cc7-4b2c-871c-3d7424fae50c")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
16 changes: 16 additions & 0 deletions Behavioral_Patterns/Observer_Design_Pattern/Website.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Observer_Design_Pattern
{
public class Website : IObserver
{
public void Update()
{
Console.WriteLine("The new news has been added to the website.");
}
}
}
7 changes: 7 additions & 0 deletions Design_Patterns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Command_Design_Pattern", "B
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mediator_Design_Pattern", "Behavioral_Patterns\Mediator_Design_Pattern\Mediator_Design_Pattern.csproj", "{89783D14-ECD8-4E4D-B989-661C2CD39A0B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Observer_Design_Pattern", "Behavioral_Patterns\Observer_Design_Pattern\Observer_Design_Pattern.csproj", "{05577F65-2CC7-4B2C-871C-3D7424FAE50C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -135,6 +137,10 @@ Global
{89783D14-ECD8-4E4D-B989-661C2CD39A0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89783D14-ECD8-4E4D-B989-661C2CD39A0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89783D14-ECD8-4E4D-B989-661C2CD39A0B}.Release|Any CPU.Build.0 = Release|Any CPU
{05577F65-2CC7-4B2C-871C-3D7424FAE50C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05577F65-2CC7-4B2C-871C-3D7424FAE50C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05577F65-2CC7-4B2C-871C-3D7424FAE50C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05577F65-2CC7-4B2C-871C-3D7424FAE50C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -160,6 +166,7 @@ Global
{06E51817-B94D-4B5D-8D29-1467BBC5F9C9} = {10745606-4276-4495-9FCF-AE66FC290967}
{59B75CF2-DD4C-4430-87C6-3D76CBD2B1D6} = {10745606-4276-4495-9FCF-AE66FC290967}
{89783D14-ECD8-4E4D-B989-661C2CD39A0B} = {10745606-4276-4495-9FCF-AE66FC290967}
{05577F65-2CC7-4B2C-871C-3D7424FAE50C} = {10745606-4276-4495-9FCF-AE66FC290967}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27914C2F-2242-4208-A01C-EEA1986870B6}
Expand Down

0 comments on commit 4372bfd

Please sign in to comment.