TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kil Gore
NA
9
729
How to implement Interface in Mainwindow
Jul 8 2019 5:43 AM
Hi,
I'm rewriting my project, so it's easier to edit in future, and want to implement interface.
I've implemented the interface, but it doesn't work in MainWindow, I'm not able to call the method.
So I've tried to use the PalindromeChecker as the default implementation PalindromeChecker = new PalindromeChecker(); , so I can call the method but it didn't work.
interface
ICheckPalindrome
{
bool
IsPalindrome(
string
text);
}
public
class
PalindromeChecker : ICheckPalindrome
{
///
/// Method for checking if the word/text is a palindrome.
///
public
bool
IsPalindrome(
string
text)
{
......
//Code
}
}
}
namespace
TextChecker
{
///
/// Interaction logic for MainWindow.xaml
///
public
partial
class
MainWindow : Window
{
public
MainWindow()
{
InitializeComponent();
lblInput.Foreground = Brushes.ForestGreen;
lblResult.Foreground = Brushes.ForestGreen;
lblTitel.Foreground = Brushes.ForestGreen;
}
///
/// User input and checking the input if the word a palindrome is.
///
private
void
InputText_TextChanged(
object
sender, TextChangedEventArgs e)
{
string
text = InputText.Text;
bool
isPalindrome = PalindromeChecker.IsPalindrome(text);
OutputText.Text = text + (isPalindrome ?
" is a palindrome"
:
" is NOT a palindrome"
);
if
(InputText.Text ==
string
.Empty)
{
OutputText.Clear();
}
}
private
void
ButtonClicked(
object
sender, RoutedEventArgs e)
{
SubWindow subWindow =
new
SubWindow();
subWindow.Show();
}
}
}
public
class
PalindromeChecker : ICheckPalindrome
{
///
/// Method for checking if the word/text is a palindrome.
///
public
bool
IsPalindrome(
string
text)
{
int
min = 0;
int
max = text.Length - 1;
while
(
true
)
{
if
(min > max)
{
return
true
;
}
char
a = text[min];
char
b = text[max];
if
(a != b)
{
return
false
;
}
min++;
max--;
}
}
}
Reply
Answers (
4
)
Should Models return Copies of Data?
my wpf application crashing